日期:2014-05-17  浏览次数:20430 次

请问SQL 当中如何查询到重复数据时只显示的重复值
大致表结构如下. 
 id      type      values
  0       0          红茶
  1       0          绿茶
  2       0          奶茶

希望结果如下.
 type       values
  0          红茶
             绿茶
             奶茶

disitinct关键字 不符合要求, 暂时毫无头绪.!!
   希望各路豪杰 帮帮忙啊,!!
SQL

------解决方案--------------------

declare @tab table
(
id int,
[type] int,
[values] nvarchar(50)
)

insert into @tab(id,[type],[values])
select 0,0,'红茶' union all
select 1,0,'绿茶' union all
select 2,0,'奶茶' union all
select 3,1,'a茶' union all
select 4,1,'b茶' union all
select 5,1,'c茶' 

select case when pg=1 then [type] else null end as [type],[values] from
(
select row_number() over(partition by [type] order by id asc) as pg,* from @tab
) t


/-********-/
type    values
0 红茶
NULL 绿茶
NULL 奶茶
1 a茶
NULL b茶
NULL c茶