我使用一個查詢來獲取結果的GridView案例語句的WHERE子句
SELECT DISTINCT
Order_Header.Id, Order_Header.Payment_Id, Order_Header.Order_No
FROM
Order_Header
INNER JOIN
Order_Shipping_Detail ON Order_Header.Id = Order_Shipping_Detail.Order_Id
LEFT OUTER JOIN
cod_orders ON cod_orders.Order_Id = Order_Header.Id
WHERE
Status = 2
不過,我需要返回所有的訂單,其中狀態= 2和訂單,其中付款編號是鱈魚(也狀態= 2 )和cod_orders.Is_confirmed = 1。
我可以爲此使用CASE語句嗎?
但是,如果我嘗試這樣做,我正在實現我的結果。
SELECT DISTINCT Order_Header.Id, order_Header.Payment_Method_Id,Order_Header.Order_No
FROM Order_Header INNER JOIN Order_Shipping_Detail
ON Order_Header.Id = Order_Shipping_Detail.Order_Id
LEFT JOIN cod_orders
ON cod_orders.Order_Id = Order_Header.Id
WHERE Status = 2 and Payment_Method_Id != 6
UNION
Select DISTINCT Order_Header.Id, order_Header.Payment_Method_Id,Order_Header.Order_No
FROM Order_Header INNER JOIN Order_Shipping_Detail
ON Order_Header.Id = Order_Shipping_Detail.Order_Id
LEFT JOIN cod_orders
ON cod_orders.Order_Id = Order_Header.Id
WHERE Status = 2 AND cod_orders.Is_Confirmed = 1
我可以將它們合併爲一個查詢嗎?
它是更好,如果你提供的樣本數據和有關 –
預期輸出你的'WHERE'試圖'CASE'聲明? – Fabio