注意 :|,: 是特殊符号,要用 "\\|", "\\;"来表示. 一行转多行 usertags 里面有很多项,每项之间以逗号分隔 create table tag_count2 as select tag,count(gid) from ( select gid,tag from (select b.gid ,b.usertags from zhangb.gid_tags b group by b.gid,b.usertags) a lateral v
--将行转为字符串 select stuff((select top 20 ','+ QQ from dl_QQ where uiid=1 order by tim desc for xml path('')),1,1,'') -- ============================================= -- Description: 将字符串转为表格 /* 例:select * from [f_split]('spu0987*5//spu0988*5/spu0989*5',
1.多行转一行 多行转一行可以通过concat_ws(',',collect_set(col_name)) as col_new的方式实现,可以参考:https://www.cnblogs.com/shujuxiong/p/9564556.html select id , concat_ws(',',collect_set(col_name)) as col_new from table_name group by id ; 2.一行转多行 一行转多行通过把原字段中的多个值拆分并转成多条记录的方
一.原数据:多行有序 SELECT CC.techname FROM PPEflow BB LEFT JOIN pubgyxxb CC ON BB.techno = CC.techno ORDER BY BB.globalOrder 二.转换后数据: SELECT '[' + CC.techname + ']-→' + '' FROM PPEflow BB LEFT JOIN pubgyxxb CC ON BB.techno = CC.techno ORDER BY BB.globalOrder
sql多行合并成一行 sql server SELECT [activityId], --STUFF( (SELECT ',' + Cast(A.phone AS varchar) FROM aaa A WHERE A.activityId=B.activityId FOR XML PATH('')) --,1,1,'') AS phonesFROM aaa BGROUP BY [activityId] mysql SELECTactivityId, group_concat(DISTINCT
数据库结构如图: 而我想让同一个人的不同成绩变成此人在这一行不同列上显示出来,此时分为2中展现: 第一种展现如图----[多行变一列](合并后的数据在同一列上): sql如下: select name ,group_concat(sore Separator ';') as score from stu group by name 第二种展现如图----[多行变多列](合并后的数据在不同列上): sql如下: SELECT name , MAX(CASE type WHEN '数学' THEN
有两个导数据的需求,1.一张表里面每一个订单号可能对应多条数据,每个单号返回时间最早的那条. 2.根据条件查询某个字段并按照逗号,合并在一起. 表类似结构如下: 第一条sql:select c.Id,c.OrderNum, c.CreateTime FROM (select t.*,row_number() over(partition by t.OrderNum order by t.CreateTime ) rn from Payinfo t WHERE t.OrderNum IN('20
假如有如下表,其中各个i值对应的行数是不定的 SQL> select * from t; I A D ---------- ---------- ------------------- 1 b 2008-03-27 10:55:42 1 a 2008-03-27 10:55:46 1 d 2008-03-27 10:55:30 2 z 2008-03-27 10:55:55 2 t 200
--SELECT ff= stuff((select ','+cast(WorkOrderNo as varchar)-- FROM dbo.TB_WorkOrder c -- where tpl.ProjectID=c.ProjectID -- WHERE c.WorkOrderType=1-- for xml path('')),1,1,'')