欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql使用group_concat()列转行后去重

程序员文章站 2022-04-29 17:14:31
未去重sqlSELECTa.start_time AS “startTime”,a.end_time AS “endTime”,a.title AS “title”,a.content AS “content”,a.meetingroom_id AS “meetingroomId”,a.contact AS “contact”,a.matters AS “matters”,a.mark AS “mark”,a.id AS “id”,a.created_time AS “createdT...

未去重sql

SELECT
	a.start_time AS "startTime",
	a.end_time AS "endTime",
	a.title AS "title",
	a.content AS "content",
	a.meetingroom_id AS "meetingroomId",
	a.contact AS "contact",
	a.matters AS "matters",
	a.mark AS "mark",
	a.id AS "id",
	a.created_time AS "createdTime",
	a.processInstance_id AS "processInstanceId",
	a.meetingtype AS "meetingtype",
	a.meetinghost AS "meetinghost",
	a.meetingmethod AS "meetingmethod",
	b.ASSIGNEE_ AS "ASSIGNEE",
	a.STATUS AS "status",-- 发布后的状态
	d.NAME AS "meetingRoom.name",
	d.pic_url AS "meetingRoom.picUrl",
	GROUP_CONCAT( n.title ) AS "threeoneModelNames" 
FROM
	act_hi_taskinst b
	INNER JOIN rz_meeting a ON a.processinstance_id = b.PROC_INST_ID_
	LEFT JOIN rz_meetingroom d ON a.meetingroom_id = d.id
	LEFT JOIN rz_threeone_model n ON FIND_IN_SET( n.id, a.threeone_model_ids ) 
WHERE
	b.ASSIGNEE_ = '60b34bc00a3e4df9afd37e2384755719' 
	AND b.END_TIME_ IS NOT NULL 
GROUP BY
	a.id 
ORDER BY
	a.created_time DESC

去重sql(只需要在GROUP_CONCAT函数里面添加distinct)

SELECT
a.start_time AS "startTime",
a.end_time AS "endTime",
a.title AS "title",
a.content AS "content",
a.meetingroom_id AS "meetingroomId",
a.contact AS "contact",
a.matters AS "matters",
a.mark AS "mark",
a.id AS "id",
a.created_time AS "createdTime",
a.processInstance_id AS "processInstanceId",
a.meetingtype AS "meetingtype",
a.meetinghost AS "meetinghost",
a.meetingmethod AS "meetingmethod",
b.ASSIGNEE_ AS "ASSIGNEE",
a.STATUS AS "status",-- 发布后的状态
d.NAME AS "meetingRoom.name",
d.pic_url AS "meetingRoom.picUrl",
GROUP_CONCAT(distinct  n.title ) AS "threeoneModelNames" 
FROM
act_hi_taskinst b
INNER JOIN rz_meeting a ON a.processinstance_id = b.PROC_INST_ID_
LEFT JOIN rz_meetingroom d ON a.meetingroom_id = d.id
LEFT JOIN rz_threeone_model n ON FIND_IN_SET( n.id, a.threeone_model_ids ) WHERE
b.ASSIGNEE_ = '60b34bc00a3e4df9afd37e2384755719' 
AND b.END_TIME_ IS NOT NULL 
GROUP BY
a.id 
ORDER BY
a.created_time DESC

只需要在GROUP_CONCAT函数里面添加distinct  

本文地址:https://blog.csdn.net/qq_28322319/article/details/107290039