Can anyone help come up with an sql code for the below?
The fields are as follows:
SerialNum
GroupCode
TktType
DueDate
Amount
Examples values are:
1.
SN123456
GC0001
Start
15-OCT-2008
28,500
SN123460
GC0001
End
28-NOV-2008
-28,500
SN134050
GC0002
Start
31-OCT-2008
53,750
SN134065
GC0002
End
30-APR-2009
-53,750
SN210010
GC0004
Start
30-SEP-2008
-18,000
SN210020
GC0004
End
31-OCT-2008
18,000
I need to get the total amount per GroupCode, but only for those outstanding DueDate.
So for the above example rows, only the following will be shown in my output:
SN123460 --> GC001 --> 28500
SN134050 --> GC002 --> 53750
SN134065 --> GC002 --> -53750
SN210020 --> GC004 --> 18000
NOTE: The amounts of the End TktType are always in absolute values if the Start TktType has expired (See output #1)