I have some data that I am trying to summarize and I am thinking I will need a union query to achieve it but I am not sure. I am not that strong with union Queries so any suggestions are appreciated. My data set is as follows
From dbo_SHIPMENT_DETAIL
ORDER LINE PART_ID TRANSACTION_ID DIST_NO MATERIAL LABOR BURDEN SERVICE
100000 1 VC2-090000-1000 279935 1 18,544.01 1.83 - 881.85
100000 1 VC2-090000-1000 279935 2 18,544.01 19.05 - 1,648.51
100000 1 VC2-090000-1000 279935 3 18,544.01 19.05 - 1,758.51
100000 1 VC2-090000-1000 281074 2 37,088.01 38.10 - 3,297.03
100000 1 VC2-090000-1000 281074 3 37,088.01 38.10 - 3,517.03
What I am trying to do is group by [ORDER],[LINE],[PART_ID], AND [TRANSACTION_ID] then MAX on [DIST_NO] and chose records from [MATERIAL], [LABOR], [BURDEN], AND [SERVICE] where the above grouping and MAX applies, and lastly to create a summary column for totals. The end result would be.
ORDER LINE PART_ID TRANSACTION_ID DIST_NO MATERIAL LABOR BURDEN SERVICE TOTAL
100000 1 VC2-090000-1000 279935 3 18,544.01 19.05 - 1,758.51 20,321.57
100000 1 VC2-090000-1000 281074 3 37,088.01 38.10 - 3,517.03 40,643.14
I can get this to work by creating a queries with the needed groups/filter then creating another query that joins the previous query back to the original data but this is one of about 4 related queries that I am trying to make, all of which will have a similar situation, so I am hoping to find a way to do this in a single query to help keep things simple.
Thanks again all
From dbo_SHIPMENT_DETAIL
ORDER LINE PART_ID TRANSACTION_ID DIST_NO MATERIAL LABOR BURDEN SERVICE
100000 1 VC2-090000-1000 279935 1 18,544.01 1.83 - 881.85
100000 1 VC2-090000-1000 279935 2 18,544.01 19.05 - 1,648.51
100000 1 VC2-090000-1000 279935 3 18,544.01 19.05 - 1,758.51
100000 1 VC2-090000-1000 281074 2 37,088.01 38.10 - 3,297.03
100000 1 VC2-090000-1000 281074 3 37,088.01 38.10 - 3,517.03
What I am trying to do is group by [ORDER],[LINE],[PART_ID], AND [TRANSACTION_ID] then MAX on [DIST_NO] and chose records from [MATERIAL], [LABOR], [BURDEN], AND [SERVICE] where the above grouping and MAX applies, and lastly to create a summary column for totals. The end result would be.
ORDER LINE PART_ID TRANSACTION_ID DIST_NO MATERIAL LABOR BURDEN SERVICE TOTAL
100000 1 VC2-090000-1000 279935 3 18,544.01 19.05 - 1,758.51 20,321.57
100000 1 VC2-090000-1000 281074 3 37,088.01 38.10 - 3,517.03 40,643.14
I can get this to work by creating a queries with the needed groups/filter then creating another query that joins the previous query back to the original data but this is one of about 4 related queries that I am trying to make, all of which will have a similar situation, so I am hoping to find a way to do this in a single query to help keep things simple.
Thanks again all