明天的明天 永远的永远 未知的一切 我与你一起承担 ??

是非成败转头空 青山依旧在 几度夕阳红 。。。
  博客园  :: 首页  :: 管理

mysql 分组汇总,

Posted on 2021-11-30 15:02  且行且思  阅读(113)  评论(0编辑  收藏  举报
select real_name as 姓名, a.phone as 手机号,id_card_no as 身份证号,id_card_type as 证件类型,
a.address as 地址,f.num as 证件数量, f.card as 内含证件类型, c.name as 村小组名称, a.create_date as 注册时间
from typg_user as a
left join sys_office as c on a.office_id=c.id
left join (
select user_id,
GROUP_CONCAT(DISTINCT  
CASE  img_type
        WHEN 1 THEN  '身份证'
                WHEN 2 THEN  '户口本'
                WHEN 3 THEN  '房屋照片'
                WHEN 4 THEN  '土地证'
                WHEN 5 THEN  '不动产证'
                WHEN 6 THEN  '权属来源'
                WHEN 7 THEN  '委托证明'
                WHEN 8 THEN  '其他'
        ELSE ''
END 
ORDER  BY img_type DESC SEPARATOR '') AS card ,
count(*) as num
from typg_certificate_image
group by user_id
) as f on f.user_id=a.id
order by a.office_id desc