GBase 8s
其他
问答

GROUP BY 查询第一条问题

发表于2025-10-09 11:17:23132次浏览7个评论

根据enterprise_id和时间,查询最新时间的一条记录,这个有什么办法处理

select *

from my_log

where is_deleted = 0 and remind_type_id = 1

GROUP BY enterprise_id

order by contract_end_time desc;

评论

登录后才可以发表评论
用户头像
曾阿牛发表于 9个月前
select first 1 *

from my_log

where is_deleted = 0 and remind_type_id = 1

GROUP BY enterprise_id

order by contract_end_time desc;
GBase用户21182发表于 9个月前
帮你顶一下
一头猪发表于 9个月前
select * from (
select *
,row_number()over(partition by enterprise_id order by contract_end_time desc) rn
from my_log
where is_deleted = 0 and remind_type_id = 1
)t where rn=1
Jackie Liu发表于 9个月前
@一头猪:谢谢
GBase用户21182发表于 9个月前
帮你点赞
GBase用户21143发表于 9个月前
优秀啊
用户头像
levvel发表于 9个月前
评论是对发帖人的一种尊重