|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I need help with a SELECT Statement.
I have a WCLASS TABLE WITH THREE ENTRIES. AN INBOUND TABLE WHERE I AM ONLY CONCERNED WITH THE DATE AND TICKET INFORMATION, AND IPDETAIL WHICH CONTAINS THE VALUES I WANT. WCLASS CONTAINS a WCLASS ID which allows me to join it to IPDETAIL. IPDETAIL contains TICKET which allows me to join it to INBOUND. There may or may not be values in INBOUND or IPDETAIL but I want the IDs displayed anyway and if another WCLASS was found for that date have the same date for the rest of the Weight Classes. I want to create a result set as follows: (WCLASS = A, IPDETAIL=B, INBOUND = C) A.WCLASS C.DATE SUM(B.QUANTITY) SUM(B.AMOUNT) 1 9/12 12 120.00 2 9/12 NULL NULL 1 9/13 13 130.00 2 9/13 14 140.00 1 9/14 NULL NULL 2 9/14 15 150.00 |
|
#2
|
|||
|
|||
|
what have you tried already?
|
|
#3
|
|||
|
|||
|
This is what I tried so far...
Select Wclass.id, Inbound.date, Count(ipdetail.wclass) As Count, Sum(ipdetail.quantity) As Quantity, Sum(ipdetail.amount) As Amount From Inbound Left Outer Join Ipdetail On Inbound.ticket = Ipdetail.ticket Right Outer Join Wclass On Ipdetail.wclass = Wclass.id Group By Wclass.id, Inbound.date
|
|
#4
|
||||
|
||||
|
uh oh
i never could wrap my head around a query that mixes left and right joins just too logically complex for me, i guess mhepner, your explanation of the tables is not enough for me to understand how they are related -- perhaps you could give a few sample rows from each table also, the comment "if another WCLASS was found for that date have the same date for the rest of the Weight Classes" makes no sense to me at all sorry |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Need help with SELECT STATEMENT |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|