我有一個表如下:編寫排序查詢
Job Quantity Status
-----------------------
1 100 OK
2 400 HOLD
3 200 HOLD
4 450 OK
5 300
6 500
我想我的結果將如下圖所示:
Job Quantity Status
----------------------
4 450 OK
2 400 HOLD
1 100 OK
3 200 HOLD
6 500
5 300
我創造了這個查詢,但它不工作時,表包含其中status
列爲空
SELECT
Job,
Quantity,
Status
FROM
myTable
ORDER BY CASE
WHEN QUANTITY >= 400 AND STATUS = 'OK' THEN 1
WHEN QUANTITY >= 400 AND STATUS = 'HOLD' THEN 2
WHEN QUANTITY < 400 AND STATUS = 'OK' THEN 3
WHEN QUANTITY >= 400 AND STATUS = 'HOLD' THEN 4
WHEN QUANTITY >= 400 AND STATUS = '' THEN 5
WHEN QUANTITY < 400 AND STATUS = '' THEN 6
END
檢查IS NULL而不是'',看看它是否有所作爲。 –