Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

I have a table containing different materials masses and round numbers over different periods of the day. Samples are taken at all different times.
Basically I would like to add the sample analysis for similiar rounds together, and display however the latest sample date.

To illustrate:

Table:

Date_Time Round No Batch_Mass

17/02/2012 15:42:35 16 500
17/02/2012 15:38:35 16 400
17/02/2012 15:33:35 15 200


The correct output would be:

Date_Time Round No Batch_Mass

17/02/2012 15:42:35 16 900
17/02/2012 15:33:35 15 200

Basically, the latest time for round number 16 was 17/02/2012 15:42:35 and the cumulative mass was 900

Thanks Guys!!
Posted

Dear Friend,

Apply the group by clause on the round number it will bring the result you require.

http://www.tizag.com/sqlTutorial/sqlgroupby.php[^]

Thanks
 
Share this answer
 
Dear Varun,


Thank you for the answer.

I have tried using this , initially it did not exactly work, but i just used the max sample_date and it worked perfectly.

SQL
SELECT  ROUND_NUMBER,sum(BATCH) as total, max(sample_date) as latest
FROM test
GROUP BY round_number;


ROUND_NUMBER TOTAL LATEST
---------------------- ---------------------- -------------------------

16 900 2012-02-17 09:02:43
15 200 2012-02-17 08:02:14

Thanks..
 
Share this answer
 
Comments
Varun Sareen 17-Feb-12 4:33am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900