我有一个按入境日期排序的清单:
让我们说我现在添加:
在当前查询中,列表如下所示:
请参阅http://sqlfiddle.com/#!9/8d61d7/2
我需要结果如下:
因此,初始排序是由created_at进行的,但是JOB B,fr-FR现在低于JOB B,en-GB记录。
对于错综复杂的解释感到抱歉......
答案 0 :(得分:1)
如果是这种情况,我宁愿使用UNION ALL并在select语句中添加“id”。 这是代码
SELECT *
FROM (
select 1 as id, name, job, created_at from yourtable where created_at <= '2016-01-12 08:10:00'
union all
select 2 as id, name, job, created_at from yourtable where job = 'fr-FR'
union all
select 3 as id, name, job, created_at from yourtable where created_at = '2016-01-12 08:20:00'
) x
order by x.id, x.created_at