Q: 想实现日期由近及远排序显示,同时把日期空放在最前面。但是,使用:Select * from
table order by date DESC时,空值是放在最后的。请问如何实现?
A: Select * from
table order by case when date is null then getdate() else date end DESC
Q: 我要求不能显示相同记录而加入DISTINCT:
Select DISTINCT * from
table order by case when date is null then getdate() else date end DESC
但是出错:如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中。
如何解决呢?
A: Select * From
(Select DISTINCT * from tableName) AS TABLE order by case when TABLE.date is null then getdate() else TABLE.date end DESC
table order by date DESC时,空值是放在最后的。请问如何实现?
A: Select * from
table order by case when date is null then getdate() else date end DESC
Q: 我要求不能显示相同记录而加入DISTINCT:
Select DISTINCT * from
table order by case when date is null then getdate() else date end DESC
但是出错:如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中。
如何解决呢?
A: Select * From
(Select DISTINCT * from tableName) AS TABLE order by case when TABLE.date is null then getdate() else TABLE.date end DESC