Link to home
Start Free TrialLog in
Avatar of AndyC1000
AndyC1000

asked on

Query to sum over two fields

Dear all,

I'm not sure how to create query to sum over two fields.  If the dist_no and i_datatime is the same sum the fields total_dollar_loss, total_ha and appliance_count.

i.e. instead of

02  2002/01/02  0  2  3
02  2002/01/02  1  0  5

the output should produce:

02  2002/01/02  1  2  8


 
SELECT s.dist_no, Format(s.i_datetime,"yyyy/mm/dd") AS Period, Sum(s.total_dollar_loss) AS TotDollarLoss, Sum(s.total_ha) AS TotHectare, Sum(s.appliance_count) AS TotAppCount INTO DailyTotalTable
FROM DataResults AS s
GROUP BY s.dist_no, Format(s.i_datetime,"yyyy/mm/dd");

Open in new window


Thanks
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Try this:
SELECT s.dist_no, Format(s.i_datetime,"yyyy/mm/dd") AS Period, Sum(s.total_dollar_loss) AS TotDollarLoss, Sum(s.total_ha) AS TotHectare, Sum(s.appliance_count) AS TotAppCount
FROM DataResults AS s
GROUP BY s.dist_no, Format(s.i_datetime,"yyyy/mm/dd");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of cstruwig
cstruwig

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial