mysql---group_concat 分组后排序,截取,时间格式化

select c.`name`,b.movie_names,time2 from (
select cinema_id,substring_index(group_concat(movie_id order by time1 desc separator '----'),'----',3) as movie_id,substring_index(group_concat(movie_name order by time1 desc separator '----'),'----',3) as movie_names,substring_index(group_concat(time1 order by time1 desc separator '----'),'----',3) as time2 from (
select cinema_id,movie_id,movie_name,substring_index(group_concat(DATE_FORMAT(start_time,'%Y-%m-%d %H:%i') order by start_time desc separator '----'),'----',1) as time1 from table_film_feature where city_code='110100' and movie_id in (select id from table_film_movie where publish_time > now()) group by cinema_id,movie_id
)a group by cinema_id)b ,table_film_cinema c where b.cinema_id=c.id

多字段分组后按时间倒序,截取前几个数据再拼接,并将时间格式化

了解group_concat的用法

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值