首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

请教SQL 当中怎么查询到重复数据时只显示的重复值

2013-06-19 
请问SQL 当中如何查询到重复数据时只显示的重复值大致表结构如下.idtypevalues00红茶10绿茶20奶茶希望结果

请问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奶茶
1a茶
NULLb茶
NULLc茶

热点排行