日期:2014-05-18 浏览次数:20753 次
exec( select 1 as jh, ... pivot union all d al
union all
select '' as jh ...
CREATE TABLE [TB] ( [ID] [int] IDENTITY (1, 1) NOT NULL , [ITEM] [int] NULL , [NOTE] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL , CONSTRAINT [PK_TB] PRIMARY KEY CLUSTERED ( [ID] ) ON [PRIMARY] ) ON [PRIMARY] GO INSERT INTO TB (ITEM, NOTE) SELECT 3,'XX' INSERT INTO TB (ITEM, NOTE) SELECT 3,'XX' INSERT INTO TB (ITEM, NOTE) SELECT 4,'XX' INSERT INTO TB (ITEM, NOTE) SELECT 5,'XX' INSERT INTO TB (ITEM, NOTE) SELECT 5,'XX' INSERT INTO TB (ITEM, NOTE) SELECT 6,'XX' SELECT * FROM TB /*----------------------- 3 XX 3 XX 4 XX 5 XX 5 XX 6 XX */ SELECT ITEM=CASE WHEN ID=( SELECT MIN(ID) FROM TB WHERE ITEM=A.ITEM ) THEN RTRIM(ITEM) ELSE '' END, NOTE FROM TB AS A ORDER BY ID /* ITEM NOTE ------------ -------------------- 3 XX XX 4 XX 5 XX XX 6 XX SELECT ITEM, NOTE FROM ( SELECT RTRIM(ITEM) AS ITEM,NOTE,ITEM AS order1,0 AS order2 FROM TB UNION ALL SELECT '','',ITEM,1 FROM TB GROUP BY ITEM ) AS A ORDER BY order1,order2 3 XX 3 XX 4 XX 5 XX 5 XX 6 XX
------解决方案--------------------
有点棘手 帮顶
------解决方案--------------------
不太明白!帮顶!
------解决方案--------------------
老师的
------解决方案--------------------
一般这种我都在前台实现
------解决方案--------------------
看了半天,还是不明白
------解决方案--------------------
这功能应该交给前台去做!定!
------解决方案--------------------