The CREATE TABLE ` test ` (
` id ` int the NOT NULL AUTO_INCREMENT,
` with ` date NOT NULL,
` store_id ` varchar (64) NOT NULL,
` money ` decimal (10, 2) NOT NULL,
` type ` tinyint (4) NOT NULL,
The PRIMARY KEY (` id `)
);
Insert data:
The 2020-03-12, 111, 500 1
The 2020-03-12 111 800 2
The 2020-03-12 222 900 2
I want to follow with and store_id group at the same time, after the group is according to the type descending, in up to find a lot of plan, are not effective, my SQL is as follows:
Select * from (
Select * from the test order by type desc) r group by with, store_id.
The results are as follows:
The 2020-03-12, 111, 500 1
The 2020-03-12 222 900 2
This is a problem, the first article data, I want money is 800, because of the type 2 is bigger than 1
CodePudding user response:
select * from the test group by with, store_id