我有四个表employees、associations_employees、associations、association_items。下面的选择查询生成了连接行。
- 注意:我为SQL和Coldfusion语言制作了标记,这是因为我使用Coldfusion作为我的脚本语言。我不确定我应该依赖SQL还是使用我的脚本语言。**
- 查询**
SELECT AE.userid, E.firstname,
A.title, AI.itemvalue
FROM associations_employees AE
INNER JOIN employees E on E.userid = AE.useridFK
INNER JOIN associations A on A.associationid = AE.associationidFK
INNER JOIN association_items AI on AI.associationidFK = AE.associationidFK
- 电流选择输出**
userID firstname title itemvalue
------ --------- ----- ---------
5603 Jesh Learner Type Family Literacy
5603 Jesh Learner Type Elementary School
5603 Jesh Learner Type Academic
5603 Jesh Personnel Type Staff
5605 jennone Personnel Type Site Supervisor
5605 jennone Personnel Type Rops member
5607 Sharon Personnel Type Rops member
5607 Sharon Personnel Type Site Supervisor
5607 Sharon Mentor Type High School
5607 Sharon Mentor Type Op. Read
5607 Sharon Mentor Type Enrichment
5607 Sharon Mentor Type General
正如您所注意到的,除了"itemvalue"列之外,有多个行是相似的。我需要将这些行合并以生成以下结果。
- 所需产出**
userID firstname title itemvalue
------ --------- ------ ---------
5603 Jesh Learner Type Family Literacy;Elementary School;Academic
5603 Jesh Personnel Type Staff
5605 jennone Personnel Type Rops member;Site Supervisor;Staff
5607 Sharon Personnel Type Rops member;Site Supervisor
5607 Sharon Mentor Type Enrichment;General;High School;Op. Read
3条答案
按热度按时间kulphzqa1#
您可以使用STUFF方法来实现这一点:
这还没有经过测试,所以可能需要一些微调。
hmae6n7t2#
如果您需要ColdFusion解决方案,cfoutput的group属性将起作用。步骤1是向查询中添加order by子句。
接下来是cfoutput标记。
这是基本的方法,你必须添加格式,并弄清楚如何从itemvalue列表中排除尾部的分号。
zsbz8rwp3#
你可以使用类似于Dan的数组方法,数组可能更快