文章目录
1.根据用户分组获取时间最大的一条数据
select
substring_index(group_concat(id order by create_time desc), ',', 1) as id
from
og_elderly_album oea
group by
elderly_info_id
2.查询某年某月的数据
# 使用日期相关函数=判断
select
date_format('2022-9-1', '%Y-%m');
select
year('2022-9-1');
select
month ('2022-9-1');
3.设计数据表更新时间CURRENT_TIMESTAMP

4.find_in_set(str, strlist)函数

5.order by 自定义排序
select
in_status ,
update_time
from
elderly_info
order by
field(in_status, 2, 0, 4, 1) ,
update_time desc

本文介绍了SQL中的一些实用查询技巧,包括如何根据用户分组获取时间最大的一条数据,查询特定年月的数据,以及如何设计数据表的更新时间字段。同时,讲解了find_in_set函数的使用和自定义排序的实现方法,对于数据库管理和查询优化具有参考价值。

被折叠的 条评论
为什么被折叠?



