假设我们有桌子
身份证、头衔、日期
我需要建立1个查询:
select date = TODAY, order by id
select data < TODAY, order by date desc,
select data > TODAY, order by date asc,
我认为您需要使用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示例。
祝你好运。