日期:2014-05-17 浏览次数:20687 次
SELECT * FROM ad WHERE 1=1???
ORDER BY case when DATEDIFF(dd,adendtime,getdate())>0 then adendtime end asc,intid desc
SELECT top 10 * FROM ad WHERE adendtime>=getdate() order by adendtime desc
DROP TABLE #temp
CREATE TABLE #temp(adendtime DATETIME, id INT )
INSERT #temp
SELECT '2013-8-29',1 UNION ALL
SELECT '2013-8-29',2 UNION ALL
SELECT '2014-7-31',3 UNION ALL
SELECT '2015-6-30',4 UNION ALL
SELECT '2013-8-29',5 UNION ALL
SELECT '2014-2-26',6 UNION ALL
SELECT '2014-6-19',7 UNION ALL
SELECT '2013-10-1',8 UNION ALL
SELECT '2012-2-17',9 UNION ALL
SELECT '2010-3-9',10
SELECT *
FROM #temp
WHERE 1 = 1
ORDER BY (CASE WHEN adendtime BETWEEN GETDATE() AND GETDATE()+10 THEN adendtime WHEN adendtime > GETDATE() THEN adendtime ELSE '9999-12-31' END), id DESC
/*
adendtime id
2013-08-29 00:00:00.000 5
2013-08-29 00:00:00.000 2
2013-08-29 00:00:00.000 1
2013-10-01 00:00:00.000 8
2014-02-26 00:00:00.000 6
2014-06-19 00:00:00.000 7
2014-07-31 00:00:00.000 3
2015-06-30 00:00:00.000 4
2010-03-09 00:00:00.000 10
2012-02-17 00:00:00.000 9
*/