Hi I need some help with a join.
The first query returns correct data. I want modify the query to pull data to add another colum called minamount.
The second query below pulls the correct minamount data.
shipmenid = shipmentid in both tables.
Also scac in tabel quotes is the same as custscac in table quoteaccscharge
Table quoteaccscharge may have data polulated for the shipmentid or it may not. It may have one or more rows of data populated for th shipmentid. If no data is present a return of zero would help.
the inner select in the second query is the same as the 1st query for the most part as far as the From, where, and clauses.
I hope there's enough info here. Thanks
SELECT Q.shipmentid , Q.quotedate, Q.scac,
convert(decimal(5,2), Q.totalCharge) as totalcharge
FROM quotes Q
WHERE Q.cid = '14'
AND Q.chosen = '1'
ORDER BY Q.quotedate desc
Shipmentid scac totalcharge
2010072400004 SEFL 88.00
2010072400003 SEFL 100.33
2010041300007 WTVA 80.07
2010041300004 WTVA 80.07
2010031700006 ODFL 124.91
2010031500002 VITR 170.46
2010030200004 VITR 96.47
2010021200006 WTVA 155.96
2010012100005 WTVA 122.96
2010011900005 VITR 131.45
select sum(minamt) as minamt,custscac, shipmentid
from quoteaccscharge where shipmentid in
(SELECT shipmentid
FROM quotes
WHERE cid = '14'
AND chosen = '1')
group by custscac, shipmentid
ORDER by custscac
minamt custscac shipmentid
146.00 FXFE 2010072400003
95.00 HMES 2010072400003
105.00 ODFL 2010072400003
65.60 RDWY 2010072400003
90.00 SEFL 2010072400003
81.00 WTVA 2010072400003
146.00 FXFE 2010072400004
95.00 HMES 2010072400004
105.00 ODFL 2010072400004
65.60 RDWY 2010072400004
90.00 SEFL 2010072400004
81.00 WTVA 2010072400004
The first query returns correct data. I want modify the query to pull data to add another colum called minamount.
The second query below pulls the correct minamount data.
shipmenid = shipmentid in both tables.
Also scac in tabel quotes is the same as custscac in table quoteaccscharge
Table quoteaccscharge may have data polulated for the shipmentid or it may not. It may have one or more rows of data populated for th shipmentid. If no data is present a return of zero would help.
the inner select in the second query is the same as the 1st query for the most part as far as the From, where, and clauses.
I hope there's enough info here. Thanks
SELECT Q.shipmentid , Q.quotedate, Q.scac,
convert(decimal(5,2), Q.totalCharge) as totalcharge
FROM quotes Q
WHERE Q.cid = '14'
AND Q.chosen = '1'
ORDER BY Q.quotedate desc
Shipmentid scac totalcharge
2010072400004 SEFL 88.00
2010072400003 SEFL 100.33
2010041300007 WTVA 80.07
2010041300004 WTVA 80.07
2010031700006 ODFL 124.91
2010031500002 VITR 170.46
2010030200004 VITR 96.47
2010021200006 WTVA 155.96
2010012100005 WTVA 122.96
2010011900005 VITR 131.45
select sum(minamt) as minamt,custscac, shipmentid
from quoteaccscharge where shipmentid in
(SELECT shipmentid
FROM quotes
WHERE cid = '14'
AND chosen = '1')
group by custscac, shipmentid
ORDER by custscac
minamt custscac shipmentid
146.00 FXFE 2010072400003
95.00 HMES 2010072400003
105.00 ODFL 2010072400003
65.60 RDWY 2010072400003
90.00 SEFL 2010072400003
81.00 WTVA 2010072400003
146.00 FXFE 2010072400004
95.00 HMES 2010072400004
105.00 ODFL 2010072400004
65.60 RDWY 2010072400004
90.00 SEFL 2010072400004
81.00 WTVA 2010072400004