Created
May 7, 2014 19:18
-
-
Save cavebatsofware/79ca2d6974bf484f11a1 to your computer and use it in GitHub Desktop.
IFSQL... if only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
d.order_id AS OrderID, | |
o.ship_date AS ShipDate, | |
a.shipping_company AS ShippingCompany, | |
a.shipping_city AS ShippingCity, | |
a.shipping_state AS ShippingState, | |
a.shipping_zip AS ShippingZip, | |
d.client_reference AS ClientReference, | |
m.carrier AS Carrier, | |
IF(ISNULL(bo.bol_id), | |
COUNT(*), | |
(SELECT | |
SUM(i.package_qty) | |
FROM | |
bol_item i | |
WHERE | |
i.bol_id = bo.bol_id | |
GROUP BY i.bol_id)) AS Cartons, | |
IF(ISNULL(bo.bol_id), | |
SUM(p.actualweight), | |
(SELECT | |
SUM(i.weight) | |
FROM | |
bol_item i | |
WHERE | |
i.bol_id = bo.bol_id | |
GROUP BY i.bol_id)) AS Weight, | |
IF(ISNULL(bo.bol_id), | |
SUM(p.customercharge), | |
(SELECT | |
b.customer_cost | |
FROM | |
bol b | |
WHERE | |
b.bol_id = bo.bol_id)) AS Charges | |
FROM | |
orders o | |
INNER JOIN | |
order_details d ON o.order_id = d.order_id | |
INNER JOIN | |
order_address a ON o.order_id = a.order_id | |
INNER JOIN | |
shipping_methods m ON d.shipment_method_id = m.shipping_method_id | |
INNER JOIN | |
shippedorderpackages p ON d.order_id = p.orderid | |
LEFT OUTER JOIN | |
bol_order bo ON d.order_id = bo.order_id | |
WHERE | |
o.status = 'Shipped' AND o.ship_date BETWEEN '2014-03-01' AND '2014-03-31' AND o.client_id = 'DORISH' | |
GROUP BY o.order_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment