我有一个如下表:
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