sql - SUM after COUNT and Group By MYSQL -


i want ask sql in mysql. im stack on 1 hour :(
have sql :

    select tzl.ismissed, count(tzl.chatid) amount tbllog tzl group tzl.ismissed 

and result :

| ismissed | amount | |        0 |    100 | |        1 |    500 | 

i want add 1 more column after amount column, let name of new column sumamount.
want sumamount value sum of amount column.

| ismissed | amount | sumamount |
| 0 | 100 | 600 |
| 1 | 500 | 600 |

i try sql below :

select     tbl.*,sum(tbl.amount) sumamount     (         select             tzl.ismissed,             count(tzl.chatid) amount                     tbllog tzl         group             tzl.ismissed     ) tbl group tbl.ismissed  rollup 

but rollup result add new 1 row, not column. can teach me ? answer

there several ways approach this. calculate value in from clause:

select tzl.ismissed, count(tzl.chatid) amount, tt.sumamount tbllog tzl cross join      (select count(*) sumamount tbllog) tt group tzl.ismissed, tt.sumamount; 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -