Home > database >  Why only a select group?
Why only a select group?

Time:12-13

Generating test data:

 CREATE TABLE ` myquote ` (
Unsigned ` id ` int (8) the NOT NULL AUTO_INCREMENT,
` code ` text COLLATE utf8mb4_unicode_ci,
` date ` date DEFAULT NULL,
` open ` double DEFAULT NULL,
The PRIMARY KEY (` id `)
);

INSERT INTO myquote (` code `, ` date `, ` open `)
VALUES (' a ', '2020-01-01', 10),
(' a ', '2021-01-01', 20),
(' a ', '2022-01-01', 30);


With group by group, select

 select code, date, open the from myquote group by code. 
+ + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - +
| code | date | open |
+ + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - +
| | 2020-01-01 | | 10 a.
+ + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - +
1 row in the set (0.00 SEC)


Why the result is not
 + - + - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - + 
| | id code | date | open |
+ - + - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - +
| 1 | a | the | | 10 2020-01-01
20 | | 2 | | 2021-01-01 | a
| 3 | a | the | | 30 2022-01-01
+ - + - + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - +
3 rows in the set (0.00 SEC)


The other two also meet the situation, please talk about deeper, thank you.
  • Related