sql - Suggest me query for count in MySql--I'm not getting proper output -
i have 1 table in mysql below.
state marketid ca ind co ind ca grp ca grp i want select data count , total of count(should below).
state marketid count totalcountind ca ind 1 2 co ind 1 currently using below query. not giving right output.
select state,marketid,count(*),sum(case marketid when 'ind' 1 else 0 end) totalcountind batchreport marketid='ind' group state,marketid; +-------+----------+----------+---------------+ | state | marketid | count(*) | totalcountind | +-------+----------+----------+---------------+ | ca | in | 1 | | | co | in | 1 | | |+-------+----------+----------+---------------+
this give result closer 1 want difference repeat totalcountind
select state, marketid, count(1) totalcount, ( select count(1) batchreport marketid = bp.marketid ) totalcountind batchreport bp marketid = 'ind' group state, marketid the result like:
state marketid totalcount totalcountind ca ind 1 2 co ind 1 2
Comments
Post a Comment