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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -