SQL group by issue when i try to get some info -
i can not figure out: have table called importantarecords fields market, zip5, mhi, mhv, thetable , want group records zip5 have thetable = 'mg'… tried :
select a.market,a.zip5,count(a.zip5),a.mhi,a.mhv,a.thetable (select * importantarecords thetable = 'mg') group a.zip5
but gives me classic error not aggrefate function
and tried this:
select market,zip5,count(zip5),mhi,mhv,thetable importantarecords thetable = 'mg' group zip5
and same thing…
any ?
you did not state database using if getting error columns not being in aggregate function, might need add columns not in aggregate function group by
:
select market, zip5, count(zip5), mhi, mhv, thetable importantarecords thetable = 'mg' group market, zip5, mhi, mhv, thetable;
if grouping additional columns alters result expecting, use subquery result:
select i1.market, i1.zip5, i2.total, i1.mhi, i1.mhv, i1.thetable importantarecords i1 inner join ( select zip5, count(*) total importantarecords thetable = 'mg' group zip5 ) i2 on i1.zip5 = i2.zip5 i1.thetable = 'mg'
Comments
Post a Comment