大海话语 2022-01-30 16:29 采纳率: 87.9%
浏览 78
已结题

Mysql中如何查询 以某一列为条件的,再加最新更新时间的那一条数据

Mysql中如何查询 以某一列为条件的,再加最新更新时间的那一条数据
下面是我写的查询的,是有问题的

最开始是这样写
select * from adverts where large_categories = #{largeCategories}
       and small_categories = #{smallCategories}
       and MAX(update_time) 

后来是下面这样写,也不对

 select * , MAX(update_time) from adverts where large_categories = #{largeCategories}
       and small_categories = #{smallCategories}
  • 写回答

4条回答 默认 最新

  • prince_zxill 2022-02-03 14:43
    关注
    SELECT ID,USER_ID,problems,last_updated_date  FROM  (select * from t_iov_help_feedback  order by USER_ID, LAST_UPDATED_DATE DESC) b GROUP BY b.USER_ID;
    关联查询 on后跟了两个条件
    select * from (select USER_ID,MAX(last_updated_date) group by USER_ID) as temp left join t_iov_help_feedback  as t on temp.USER_ID=t.USER_ID and temp.last_updated_date=t.last_updated_date;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 2月13日
  • 已采纳回答 2月5日
  • 修改了问题 1月30日
  • 创建了问题 1月30日