0

我想订购 mysql 查询的结果

1) 显示与给定条件匹配的第一个条目并随机排序

2) 然后显示按日期 desc 排序的其余结果

我已经试过了:

Select * from post inner join user on post.user_id = user.id order by user.type = "top" desc, created desc;

非常感谢

4

1 回答 1

1

使用case声明

select * from post 
inner join user on post.user_id = user.id 
order by case when user.type = 'top' 
              then 1 
              else 2 
         end asc, 
         created desc;
于 2013-05-10T09:54:05.997 回答