Hi I have to make a sql query in my app but I can't solve it.
Can I get a hint so that I know how to continue?
In the table below you see the following columns
Q_ID = Quotation Number
Pos = Position quotation (Line number)
ArtNo = Article Number
Qty = Quantity quoted
Qty_Alt = Alternative quantity quoted
Price = Price @ Qty
Price_Alt = Price @ Qty_Alt
NetValue = Qty x Price
NetValue_Alt = Qty_Alt x Price_Alt
Status = Won or lost position
Q_ID Pos ArtNo Qty Qty_Alt Price Price_Alt NetValue NetValue_Alt Status
100 001 1000 10 0 100 0 1000 0 lost
100 002 1000 0 20 0 90 0 1800 lost
100 003 1000 0 30 0 80 0 2400 won
100 004 1000 0 40 0 70 0 2800 lost
100 005 2000 10 0 150 0 1500 0 lost
100 006 2000 0 20 0 140 0 2800 lost
100 007 2000 0 30 0 130 0 3900 lost
100 008 2000 0 40 0 120 0 4800 lost
Here is my problem:
I can't figure out how I can get the sum of the values of the highest quoted for each item
I will explain it:
In the table above there are two articles 1000 and 2000. The highest quantity quoted for both articles is 40 pieces. The corresponding net values are 2800 and 4800. The result of the query should be the sum of both these values = 7600
Note that the highest quantity can also be in the column Qty instead of Qty_Alt
Any help, query or hint is highly appreciated
Henk
Can I get a hint so that I know how to continue?
In the table below you see the following columns
Q_ID = Quotation Number
Pos = Position quotation (Line number)
ArtNo = Article Number
Qty = Quantity quoted
Qty_Alt = Alternative quantity quoted
Price = Price @ Qty
Price_Alt = Price @ Qty_Alt
NetValue = Qty x Price
NetValue_Alt = Qty_Alt x Price_Alt
Status = Won or lost position
Q_ID Pos ArtNo Qty Qty_Alt Price Price_Alt NetValue NetValue_Alt Status
100 001 1000 10 0 100 0 1000 0 lost
100 002 1000 0 20 0 90 0 1800 lost
100 003 1000 0 30 0 80 0 2400 won
100 004 1000 0 40 0 70 0 2800 lost
100 005 2000 10 0 150 0 1500 0 lost
100 006 2000 0 20 0 140 0 2800 lost
100 007 2000 0 30 0 130 0 3900 lost
100 008 2000 0 40 0 120 0 4800 lost
Here is my problem:
I can't figure out how I can get the sum of the values of the highest quoted for each item
I will explain it:
In the table above there are two articles 1000 and 2000. The highest quantity quoted for both articles is 40 pieces. The corresponding net values are 2800 and 4800. The result of the query should be the sum of both these values = 7600
Note that the highest quantity can also be in the column Qty instead of Qty_Alt
Any help, query or hint is highly appreciated
Henk
Last edited: