Home > database > To ask how do you write this SQL statement
To ask how do you write this SQL statement
Time:10-27
There is a table, the content is as follows:
The ID is the primary key, in the hope that query results is ID after sorting, the same name and type of continuous data of ID, realize the statistical results are as follows:
To ask god what should the implementation, thank you,
CodePudding user response:
The set @ v=null; The set @ n=0;
Select the name, type, the sum (count) as the count, If (@ v!=concat (name, type), @ n:=@ the n + 1, @ as t, n) @ v:=concat (name, type) From the table Group by t