我在MySQL查询中遇到一个问题,我必须使用attend_date中的order by子句从视图中提取一些记录,但即使可能有一些数据未填充attend_date,所以我怎样才能完成它
示例:
SELECT *
FROM vw_getengineerreview
WHERE reference_number ='xxs/xxx/00256'
ORDER BY attended_date ASC;
这给了记录可用的内容(那是正确的)但空值记录值打印在顶部,但我想在底部(当attend_date为空时)
输出低于
| Technician Name | Start Date / Time | End Date / Time | Technician Remarks |
|-------------------|-----------------------|---------------------|--------------------|
| Kasun Chathuranga | 2016-10-04 - 10:49:13 | - | |
| Kasun Chathuranga | 2016-09-06 - 17:17:02 | 2016-09-22-02:16:23 | not powering |
答案 0 :(得分:2)
SELECT *
FROM vw_getengineerreview
WHERE reference_number ='xxs/xxx/00256'
ORDER BY (attended_date IS NOT NULL) DESC, attended_date ASC
如果结果不是您想要的结果,请使用ASC
/ DESC
。
答案 1 :(得分:0)
尝试一下,这肯定会解决您的问题。
谢谢,
快乐编码。
SELECT *
FROM vw_getengineerreview
WHERE reference_number ='xxs/xxx/00256'
ORDER BY ISNULL(attended_date),attended_date ASC;