For Path

/****** Script for SelectTopNRows command from SSMS  ******/


DECLARE @table TABLE (姓名 VARCHAR(10),课程 VARCHAR(10),分数 INT)
 
insert into @table VALUES ('张三','语文',74)
insert into @table VALUES ('张三','数学',83)
insert into @table VALUES ('张三','物理',93)
insert into @table VALUES ('李四','语文',74)
insert into @table VALUES ('李四','数学',84)
insert into @table VALUES ('李四','物理',94)
 
 
SELECT * FROM @table
 
SELECT *  FROM @table PIVOT( MAX(分数) FOR 课程 IN (语文,数学,物理))a
 
 
DECLARE @table1 TABLE (姓名 VARCHAR(10),语文 INT,数学 INT,物理 INT)
 
INSERT INTO @table1 VALUES('张三',74,83,93)
 
INSERT INTO @table1 VALUES('李四',74,84,94)
 
SELECT * FROM @table1
SELECT  姓名 ,
        课程1 ,
        分数1
FROM    @table1 UNPIVOT ( 分数1 FOR 课程1 IN ( [语文], [数学], [物理] ) ) t;


SELECT TOP 1000
        [id],[GroupId],[CvNumber],[Name],[PFId],[JoinId],[Flag],[flagName],[identityName],[title]
FROM    [Ms_Mobile].[dbo].[V_UserIdentity] WHERE CvNumber=131285



    SELECT A.GroupId, A.CvNumber,(
	        
			 SELECT
			    CAST(Flag AS VARCHAR(12))+':'+identityName+',' 
			 FROM  V_UserIdentity
			 WHERE CvNumber=A.CvNumber AND GroupId=a.GroupId
			 FOR  XML PATH('')
	    ) AS C
	FROM V_UserIdentity AS A
	WHERE A.PFId=1
	GROUP BY A.CvNumber,A.GroupId;

	WITH ct1 AS (
	SELECT B.GroupId,B.CvNumber,LEFT(B.C,LEN(B.C)-1) AS flag FROM (
	    SELECT A.GroupId, A.CvNumber,(
			 SELECT
			    CAST(Flag AS VARCHAR(12))+',' 
			 FROM  V_UserIdentity
			 WHERE CvNumber=A.CvNumber AND GroupId=a.GroupId
			 FOR  XML PATH('')
	    ) AS C
	FROM V_UserIdentity AS A
	WHERE A.PFId=1
	GROUP BY A.CvNumber,A.GroupId
	) AS B 
	) 
	SELECT  * FROM ct1  WHERE ct1.CvNumber=131285



	----2009级 在职  人力资源管理,
	----人资系 副讲师
	--position 4  人资+position
	
	


DECLARE @table3  TABLE(GroupId INT,CvNumber BIGINT,Name VARCHAR(50),JoinId INT,flagName VARCHAR(1024));
INSERT INTO @table3 (GroupId,CvNumber,Name,JoinId,flagName)
SELECT GroupId,CvNumber,Name,JoinId,flagName  FROM [Ms_Mobile].[dbo].[V_UserIdentity]  WHERE PFId=1 AND GroupId<>0

SELECT * FROM  @table3


 /*
 
SELECT  B.sName,LEFT(StuList,LEN(StuList)-1) as hobby
FROM    (SELECT sName,(
                       SELECT   hobby+','
                       FROM     student
                       WHERE    sName=A.sName
                      FOR  XML PATH('')
                ) AS StuList
         FROM   student A
         GROUP BY sName
        ) B 
 
 */


 SELECT  ROW_NUMBER()OVER(PARTITION BY CvNumber,GroupId ORDER BY Flag),
        [id],[GroupId],[CvNumber],[Name],[PFId],[JoinId],[Flag],[flagName],[identityName],[title]
FROM    [Ms_Mobile].[dbo].[V_UserIdentity] WHERE CvNumber=131285

  

转载于:https://www.cnblogs.com/alphafly/p/5076290.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值