假设我们有表
id,title,date
我需要构建1个查询:
select date = TODAY, order by id
select data < TODAY, order by date desc,
select data > TODAY, order by date asc,
答案 0 :(得分:2)
我认为你需要使用UNION
和子查询:
SELECT * FROM (
SELECT *
FROM YourTable
WHERE Date(dateField) = Date(Now())
ORDER BY ID
) t1
UNION
SELECT * FROM (
SELECT *
FROM YourTable
WHERE dateField < Now()
ORDER BY dateField DESC
) t2
UNION
SELECT * FROM (
SELECT *
FROM YourTable
WHERE Date(dateField) > Now()
ORDER BY dateField
) t3
这是一个简化的SQL Fiddle示例。
祝你好运。