34,593
社区成员
发帖
与我相关
我的任务
分享
张三 xxx xxx xxx xxx
张三 xxx xxx xxx xxx
张三 xxx xxx xxx xxx
李四 xxx xxx xxx xxx
李四 xxx xxx xxx xxx
张三 xxx xxx xxx xxx
xxx xxx xxx xxx
xxx xxx xxx xxx
李四 xxx xxx xxx xxx
xxx xxx xxx xxx
select
(case px when 1 then sname else '' end) as sname,col1,col2,col3
from
(select *,rid=row_number() over (partition by sname order by getdate())from tb)t
--视图查询可以直接这段,当然版本在 2005 及其上的。
select (case when rid=1 then sname else '' end) sname,col1,col2,col3
from(
select *,rid=row_number() over (partition by sname order by getdate())
from tb
)t
-- try do it !
--可以在视图创建的时候写,也可以在视图查询的时候写,例如张三李四这个字段是 sname
create view viewname
as
select (case when rid=1 then sname else '' end) sname,col1,col2,col3
from(
select *,rid=row_number() over (partition by sname order by getdate())
from tb
)t