sql - How to use group by <<colName>> properly in MySQL? -


below data in table

| count(*) | system | |        2 | sys1   | |        7 | sys2   | |        6 | sys1   | 

i want output below

| count(*) | system | |        8 | sys1   | |        7 | sys2   | 

how do that?
below query using. can tell me wrong in this?

select *   (select count(*),system tbl1 creationdate < curdate() , creationdate >= curdate() - interval 1 day group system   union   select count(*),system tbl2 creationdate < curdate() , creationdate >= curdate() - interval 1 day group system) tbl3 group system; 

you need use sub-query achieve this:

try this:

select sum(total) `count`, system (     select count(*) total, system tbl1              creationdate < curdate()                , creationdate >= curdate() - interval 1 day group system     union      select count(*) total, system tbl2              creationdate < curdate()                , creationdate >= curdate() - interval 1 day group system ) group system 

output:

| count | system | |     8 | sys1   | |     7 | sys2   | 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -