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
Post a Comment