MySQL Forums
Forum List  »  General

Fetching the value of the last record in a group by
Posted by: Stefan Immel
Date: October 17, 2018 06:15AM

Hi
I would like to fetch the value of a certain field in the last record of a group. Is there some easy way to do that?

Example:
Item,Date,Quantity,Value
A,07/01/2018,5,13
A,08/02/2018,3,11
B,13/04/2018,7,15
A,15/05/2018,4,12
B,22/05/2018,3,9
B,12/06/2018,5,14

I would like to do something like that:

Select Item, sum(Quantity), Last(Value) from table
group by Itm
order by Date

and recieve this:
A,12,12
B,15,14

Options: ReplyQuote


Subject
Written By
Posted
Fetching the value of the last record in a group by
October 17, 2018 06:15AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.