mardi 17 février 2015

SQL Query Groupby UserID and take the first and last for duplicates

Hello I am trying to do a select of certain elements on a table. here is what my table look like Time,UsrerId,Data. Now what i want to do is for the same userid i want the first and last Value of data according to the timestamp.


Example:



Time UserID Data
8 PM 1 200
9 PM 1 300
10 PM 1 100
8 PM 2 150
9 PM 2 250
10 PM 2 350
8 PM 3 100


So my result should look like:



1 200 100
2 150 350
3 100 100

Aucun commentaire:

Enregistrer un commentaire