mysql - Counting and Grouping -


I am trying to combine and count with a database.

I have this data:

  column_a | Column_b ------------------- A | 1a. 2a. 2b | 3b 3a. 3b 3   

I want to create a column to calculate the number of rows that match the value of the column_a to a_total I am Then I want to put together the group column_b values ​​for the type of AD. The data will then output by descending a_total , then descending column_by.

I want this output:

  column_a | Column_b | A_total | BTatal --------------------------------------- A | 3 | 4 | 1a. 2 | 4 | 2a. 1 | 4 | 1b 3 | 3 | 3   

What have I got so far ...

So far I have SELECT column_a, column_b, COUNT (* ) This group from AS b_total by column_a, column_b, ORDER BY column_b, DESC, b_total DESC which puts column_b in the order with the correct b_total , but how uncertain I am Get the sum of a_total in column_a within the same question.

Any help would be great!

  test the database; Use examination; Create table T (A VARCHAR (5), BIT); INSERT T VALUE ('A', 1), ('A', 2), ('A', 2), ('B', 3), ('B', 3), ('A', 3) , ('B', 3);   

/ * query * /

  SELECT xx.a, xx.b, yy.a_total, zz.b_total (select a, bt Xx Inner Join (SELECT COUNT (a) as a_total, a FROM T group a) yy ON xx.a = yy.a INNER JOIN (SELECT COUNT (a) AS b_total, a, bf to t by group a, B) Juz on (zz.a = xx.a and zz.b = xx.b)    

Comments