sql - SUM of COUNTS MySQL -
i have following sql query
select (select count(cid) uid=45 group cid) cats (select count(cid) uid=45) cats_total
the first sub-select produces 4 rows , counts number of items in each cid. second sub-select produces 1 row , counts numbers of items total.
my problem lies in second sub-select. sql producing error because have different amounts of rows. there adjustment can make second sub-select has 4 rows, or whatever amount of rows first sub-select produces?
update: let me clarify further table need produce
+------+------------+ | cats | cats_total | +------+------------+ | 2 | 17 | | 5 | 17 | | 1 | 17 | | 9 | 17 | +------+------------+
alternative, can use union all
,
select sum(totals) grandtotal ( select count(cid) totals uid=45 group cid union select count(cid) totals uid=45 ) s
Comments
Post a Comment