Home > database >  Multiple columns, classification, statistical summary, how to do?
Multiple columns, classification, statistical summary, how to do?

Time:10-29



Excuse me everybody, how to according to the class, grade, rapid classification statistics in each field, the number of different options,

CodePudding user response:

The final results are as follows:
Primary school is grade A, grade 2019 01 class, the Chinese time (A: 30; B: 20; C: 15)
Primary school is grade A, grade 2019 01 class, mathematical length (A: 35; B: 10; C: 35)

CodePudding user response:

Data:
Id grade class Chinese time
9 A grade level 2019 01 class A
10 in a grade level 2019 01 class B
11 A grade level 2019 01 class A

Statistical language length:
Select grade, class, GROUP_CONCAT (Chinese length, ':', CNT separator '; ') AS the results from
(select grade, class, and the Chinese time, count (*) as the from CNT table
A group by grade, class, and the Chinese time)
Group by grade, class

Results:
Grade class the results
A: A first grade level 2019 01 class 2; 1
B:

Other so on

CodePudding user response:

The full version

Select grade, class, 'Chinese length' as' discipline, GROUP_CONCAT (Chinese length, ':', CNT separator '; ') AS the results from
(select grade, class, and the Chinese time, count (*) as the from CNT test2
A group by grade, class, and the Chinese time)
Group by grade, class
Union all
Select grade, class, and the 'mathematical time' as' discipline 'GROUP_CONCAT (mathematics length,' : ', CNT separator '; ') AS the results from
(select grade, class, and the mathematical time, count (*) as the from CNT test2
A group by grade, class, and the mathematical time)
Group by grade, class
Union all
Select grade, class, and the 'English time' as' discipline 'GROUP_CONCAT (English time,' : ', CNT separator '; ') AS the results from
(select grade, class, and the English time, count (*) as the from CNT test2
A group by grade, class, and the English time)
Group by grade, class