Say I have the following information in an Oracle 11g table:
Qty Production order Date and time
--- ----------------- ---------------
20 00000000000000001 12-JAN-14 00:02
20 00000000000000001 12-JAN-14 00:05
20 00000000000000001 12-JAN-14 00:07
20 00000000000000001 13-JAN-14 00:09
30 00000000000000002 12-JAN-14 00:11
30 00000000000000002 12-JAN-14 00:15
30 00000000000000002 12-JAN-14 00:20
30 00000000000000002 14-JAN-14 00:29
I would like to write a query that would return the following:
Qty Production order First Last
--- ----------------- --------------- ---------------
80 00000000000000001 12-JAN-14 00:02 13-JAN-14 00:09
120 00000000000000002 12-JAN-14 00:11 14-JAN-14 00:29
That is, the sum of the Qty column grouped by Production order, and the date/time of the first and last records for each Production order. I came up with a query that yielded this result:
Qty Production order First Last
--- ----------------- --------------- ---------------
80 00000000000000001 12-JAN-14 00:02 14-JAN-14 00:29
120 00000000000000002 12-JAN-14 00:02 14-JAN-14 00:29
Which means that the First and Last columns show the overall first and last date / time of the whole table. Please note that this is a dummy table. Sorry I am now allowed to write the actual query I came up with since work policies do not allow me to share it. Also, I tried with windowing functions such as rank() and row_number() but my user does not have enough privileges to do so. Any help or hints will be greatly appreciated.