Please explain how to get the details from the following tables!
Table1
Loc, ItemCode, DayEnd, Line, TotQty
AD, 1000, 5000, 10, 635
BW, 1100, 5010, 15, 200
AD, 1000, 5020, 10, 201
AD, 1000, 5030, 20, 350
BW, 1000, 5040, 10, 250
BW, 1100, 5040, 15, 50
AD, 1100, 5050, 15, 100
Table2
ItemCode, Desc, Base
1000, XXXXXXXXXXXXXXXXX, 10
1100, YYYYYYYYYYYYYYYYY, 20
here the output should be grouped by Loc, ItemCode and Order by DayEnd, and the TotQty from the last record if ordered by DayEnd+Line
the expected records should look like:
Loc, ItemCode, DayEnd, Line, TotQty, Desc, Base
AD, 1000, 5030, 20, 350, XXXXXXXXXXXXXXX, 10
AD, 1100, 5050, 15, 100, YYYYYYYYYYYYYYY, 20
BW, 1000, 5040, 10, 250, XXXXXXXXXXXXXXX, 10
BW, 1100, 5040, 15, 50, YYYYYYYYYYYYYYY, 20
How to write the query?