编程论坛
注册
登录
编程论坛
→
SQL Server论坛
麻烦问题请高手看看,请见图例!
tanlly12
发布于 2012-11-21 19:35, 525 次点击
SQL中,源表里ID和序号相同的记录,只要项目编号有A值,那么项目编号为其他值的记录不显示。
只有本站会员才能查看附件,请
登录
只有本站会员才能查看附件,请
登录
3 回复
#2
tanlly12
2012-11-21 19:37
按ID和序号分组,项目编号为A值,则有其他值的记录不显示;若项目编号中无A值的话,则全部显示。
#3
青春无限
2012-11-21 22:30
看看
#4
半杯清茶
2012-11-22 09:50
select t1.id,t1.xh,t1.xmbh from (select t.id,t.xh,t.xmbh,row_number() over (partition by t.id order by t.xmbh) as list from t )t1
where t1.xmbh='A' and t1.list =1
union all
select * from t where id not in (select id from t where xmbh='A')
1