Venus丶 2019-12-05 10:33 采纳率: 66.7%
浏览 311
已采纳

mysql中一张表按照两种方式排序显示

在项目中有这样一个需求:评论列表按照点赞数由高到低显示前3条,其他按照时间顺序来排列

  • 写回答

2条回答 默认 最新

  • Kevin.Y.K 2019-12-05 10:41
    关注
    第一次查询点赞数前三的ID:
    select id from t_comment order by dz_num desc limit 0,3
    
    第二次关联查询
    
    select *, 1 as isTop
    from t_comment 
    where id in (3,4,5)
    union all
    select *, 0 as isTop 
    from comment
    where id not in (3,4,5)
    order by isTop desc, create_time desc
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?