select * from b_workOrder select * from( SELECT work_order_id,work_level, roles,code FROM (SELECT work_order_id,work_level,operator_code,sqc_code,hqc_code FROM b_workOrder where sqc_code <>'') p UNPIVOT (code FOR roles IN (operator_code,sqc_code,hqc
declare @table table (name nvarchar(4))insert into @tableselect '张三' union allselect '李四' union allselect '王五' union allselect '刘三' union allselect '杨二' union allselect '胡八' union allselect '赵六' --方法1:create table #t (id int identity(1,1),name nvarch
select ptl_a01, ptl_piitem, ( ) as ptl_count, STUFF((SELECT ','+ltrim(ptl_pdid) FROM PRODUCT_TRACEABILITY_LOG , , '') AS ptl_all_pdid GROUP BY t.ptl_a01,t.ptl_piitem ORDER BY t.ptl_a01 关键字:STUFF 1.作用 删除指定长度的字符,并在指定的起点处插入另一组字符. 2.语法 STUFF ( character_
原帖:http://www.cnblogs.com/nayitian/p/3231734.html wmsys.wm_concat Definition: The Oracle PL/SQL WM_CONCAT function is used to aggregate data from a number of rows into a single row, giving a list of data associated with a specific COMMENT_BODY. In ef
前言: 由于很多业务表因为历史原因或者性能原因,都使用了违反第一范式的设计模式.即同一个列中存储了多个属性值(具体结构见下表). 这种模式下,应用常常需要将这个列依据分隔符进行分割,并得到列转行的结果. 表数据: ID Value 1 tiny,small,big 2 small,medium 3 tiny,big 期望得到结果: ID Value 1 tiny 1 small 1 big 2 small 2 medium 3 tiny 3 big 总结: 这种方法的缺点在于,我们需要一个拥有连
update批量更新某一列成其它列对应的值 postgresql 标准sql语句 update AA set name = BB.name , AA.sex = BB.sex from BB where AA.id = BB.id ; 注意不要写成 from AA,BB ,即不要把自身的表写在from后,不然会报异常 :table name specified more than once update AA set name = BB.name from AA,BB where AA.id =
在db2中遇到多行一列转为一行一列的需求时,用db2函数 LISTAGG可以实现该功能.语法如下: SELECT [分组的字段 ] , LISTAGG([需要聚合的字段名], ',') FROM [表名] GROUP BY [分组的字段名] ; 设计以下实验,阐述该函数实现行转列的方法.步骤1:用sql构造一张临时表数据如下: create table test(id BIGINT,name varchar(20)); insert into test values(1,'a')