mysql - Sum totals of two queries -
mysql - Sum totals of two queries -
i have 2 basic queries need sum totals of:
select hours, sum(hours) table name='xxx' , description='worked' select hours2, sum(hours2) table name='xxx' , description2='worked' i've tried union , me totals of each query not combine them.
table setup is:
id name hours description hours2 description2i need correlate hours description , hours2 description2 why have 2 different queries. need sum totals of hours , hours2.
first of all, missed group by, though mysql doesn't complain it, hours , hours2 values meaningless. secondly, result of union can set in derived subquery, have desired total :
select sum(hr) ( select sum(hours) hr table name='xxx' , description='worked' union select sum(hours2) hr table name='xxx' , description2='worked' )a mysql sql aggregate-functions
Comments
Post a Comment