grouping - Counting rows matching each of the multiple conditions in MySQL -


Please help me with a single query converting the data given below ...

  | ID | Status_A | Status_b | | ++++++++++++++++++++++ | | 1 | Active | Inactive |  

... in this one.

| Status_group | Counting | | +++++++++++++++++++++++ | | Status_A Active | 1 | | Status_b.novar | 1 |

Edit: If a single pass query is possible, then it would be better, besides, a question with unions passes one?

If the status can only be active or inactive , I suggest a different approach:

  SELECT sum (if (status_a = 'active', 1,0)) position_a_active, amount (if (status_a = 'inactive' Position_A_national, sum (if (position_b = 'active', 1,0)) position_b_active, sum (if (status_b = 'passive', 1, 0)) position from position_bank table  

Otherwise you may need to use the UNION approach Yes, but I want to do it in a slightly different way. First of all, you can use UNION ALL , because you do not need to remove duplicates in the result. I also use GROUP BY only once:

  SELECT status_group, FROM (SE) CONCAT ('status_a.', Status_a) AS Status_group, all select union from the table (static_group), the status of the group from the status_group, the id), the static_groups by a group  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -