select (
case when 字段2=(select top 1 字段2
from 表
where 字段1=t.字段1
order by 字段2)
then t.字段1
else ''
end
)
,
,字段2from 表 t
order by 字段1,字段2--参考:
http://community.csdn.net/Expert/topic/4385/4385030.xml?temp=.7137415
解决方案 »
- 新手请教:如何得到完全重复记录的结果集?
- 如何编写触发器
- sql 2005不能更新sysdatabases,已将allow update置为1?
- 求救
- 求助!!为什么我的text类型只能存放1023个字符啊?!
- 关于FROM 表执行顺寻的疑问
- sql数据汇总
- SQL臨時表出錯:資料庫已經有一個名為 '#t1' 的物件。
- SQLserver中对表的插入问题
- windows XP professional下安装MS SQL2000企业版,不能安装服务器端软件,怎么办?急!
- 求教简单sql,如何取字符串指定字符之后的n个字符?
- 新建用户,“指定此登分清可以访问的数据库”中没有被钩选的数据库,居然也可以访问。为什么?
from 表
where 字段1=t.字段1
order by 字段2)
then t.字段1
else ''
end
)
,字段2
from 表 t
order by 字段1,字段2
[create] table #(col1 varchar(20),col2 varchar(20))
insert into # values ('AA','200501')
insert into # values ('AA','200502')
insert into # values ('AA','200503')
insert into # values ('BB','200501')
insert into # values ('BB','200502')
insert into # values ('BB','200503')
insert into # values ('BB','200504')
go
alter table # add flag int
go
update # set flag=a.flag
from (
select *,flag=(select count(1) from (select col1 from # group by col1) a where a.col1<b.col1)
from (select col1 from # group by col1) b) a,# b
where a.col1=b.col1update # set col1 = ''
from #
where col2 not in (select min(col2) from # group by col1)select col1,col2 from #
drop table #col1 col2
-------------------- --------------------
AA 200501
200502
200503
BB 200501
200502
200503
200504(所影响的行数为 7 行)