gpt4 book ai didi

MYSQL:左连接并使用 group_concat 将外观限制为一个

转载 作者:行者123 更新时间:2023-11-30 00:24:13 25 4
gpt4 key购买 nike

我有一个这样的sql:

SELECT TASKID, TSK_STATUSID, TSK_CODE, TSK_TITLE, TSK_REF_NO, TSK_DESCRIPTION, STS_NAME, COALESCE(USR_NAME, 'None') AS TUSERNAME 
FROM T_TASK_REQUEST
LEFT JOIN T_STATUS ON T_STATUS.STATUSID=T_TASK_REQUEST.TSK_STATUSID
LEFT JOIN T_TASK_USER ON TUS_TASKID = TASKID
LEFT JOIN T_USER ON USERID = TUS_USERID
LEFT JOIN T_PROJECT ON T_PROJECT.PROJECTID=T_TASK_REQUEST.PROJECTID
WHERE TSK_STATUSID='1' AND T_TASK_REQUEST.PROJECTID='2' ORDER BY TASKID DESC LIMIT 10

当前结果是这样的 enter image description here

如何将 TASKID 分组连接到 1 行,TUSERNAME 结果为:boon|danny|jack|goh|ncc

|分隔?

在此处查看完整尺寸的 IMG:http://i.stack.imgur.com/WXH3g.jpg

最佳答案

修改后确切的工作SQL是:

SELECT TASKID, TSK_STATUSID, TSK_CODE, TSK_TITLE, TSK_REF_NO, TSK_DESCRIPTION, STS_NAME, GROUP_CONCAT(DISTINCT COALESCE(USR_NAME, 'None') SEPARATOR '|') AS TUSERNAME 
FROM T_TASK_REQUEST
LEFT JOIN T_STATUS ON T_STATUS.STATUSID=T_TASK_REQUEST.TSK_STATUSID
LEFT JOIN T_TASK_USER ON TUS_TASKID = TASKID
LEFT JOIN T_USER ON USERID = TUS_USERID
LEFT JOIN T_PROJECT ON T_PROJECT.PROJECTID=T_TASK_REQUEST.PROJECTID
WHERE TSK_STATUSID='1' AND T_TASK_REQUEST.PROJECTID='2'
GROUP BY TASKID
ORDER BY TASKID DESC LIMIT 10

感谢@John Woo

关于MYSQL:左连接并使用 group_concat 将外观限制为一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23005299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com