SQL 多行相同值,只显示第一行的数据
显示效果:1 10
1 20
1 33
1 50
2 20需要显示的效果是:1 10
20
33
50
2 20
显示效果:1 10
1 20
1 33
1 50
2 20需要显示的效果是:1 10
20
33
50
2 20
解决方案 »
- 求SQL数据填充问题
- 简单问题,求一简单的流水号生成
- sql2000的自定义函数为什么不起作用?
- 分离字符和数字
- sql server 2005的 pivot 能不能将未知的行值转成列?
- 用windows认证方式其他应用程序怎么连接到SQL SERVER2005
- 查询表与变量联合问题
- 小问题,在线等
- 有关SQLserver2000的安装问题
- 在ORACLE中如何实现类似于SQLSERVER中的SUBSCRIPTER,PUBLISH功能以使得异地之间的数据保持同步.
- sql server性能问题
- 急。。在线等!!XP sp2 安装 sql2005.无法链接到本地服务器。MSSQLSERVER已经运行了。。
with cte as
(
select row_number() over (partition by id order by id) n ,id,num from tb
)select id,num from cte where n = 1
union all
select '',num from cte where n<> 1
--假设第一列为id,第二列为num
;with cte as(
select rid=row_number() over (partition by id order by num),* from tb
)
select case when rid=1 then ltrim(id) else '' end,num from cte
create table tb
(id int ,value int)
insert into tb
select 1,10 union all
select 1,20 union all
select 1,33 union all
select 1,50 union all
select 2,20with cte as
(
select *,rowNum=ROW_NUMBER() over(partition by id order by value) from tb
)
select case when rowNum=1 then cast(id as varchar) else '' end AS id,value from cteid value
------------------------------ -----------
1 10
20
33
50
2 20(5 行受影响)
case px when 1 then ltrim(id) else '' end as id,
value
from
(select px=row_number()over(partition by id order by getdate()),* from tb) t
(id int ,value int)
insert into tb
select 1,10 union all
select 1,20 union all
select 1,33 union all
select 1,50 union all
select 2,20
;
with cte as
(
select *,rowNum=ROW_NUMBER() over(partition by id order by value) from tb
)
select case when rowNum=1 then cast(id as varchar) else '' end AS id,value from cte
记得别把那个‘;’输起。