I have a problem with sql data aggregation problem.here is the sample sql.I am using oracle database.
select pm.city cityid, to_char(pm.sampledate, 'yyyy-MM') timepoint, count(distinct me.id) mecount, count(distinct me.hotpointid) hpcount
from upme me, appmday pm
where pm.apid = me.id
and pm.sampledate between to_date('2011-11-01', 'yyyy-MM-dd') and
to_date('2012-1-31', 'yyyy-MM-dd')
group by pm.city, to_char(pm.sampledate, 'yyyy-MM')
above i get the count of my data.but i also i want to get the overall result like
select to_char(pm.sampledate, 'yyyy-MM'), count(distinct me.id), count(distinct me.hotpointid)
from upme me, appmday pm
where pm.apid = me.id
and pm.sampledate between to_date('2011-11-01', 'yyyy-MM-dd') and
to_date('2012-1-31', 'yyyy-MM-dd')
group by to_char(pm.sampledate, 'yyyy-MM')
basically i want get some result from sql ,in the same sql i want to get the count from the previous result,they both show in the result in one sql. i did not want to union these two sql ,because each sql is very slow.
did someone have a idea? or it cannot be done by one sql without union?
thank you for the reply.