这个sql怎么写?

zs1602001 2009-11-03 09:52:56
视图返回的结果,表结构如下:
A表
Id Name
1 null
1 a
1 b
2 null
2 c
3 null
4 null

id列可以重复,name列可以为空。
如果name列为空,而且id列有重复的话则删除该列,如果id列没有重复则不能删除。

上面的表返回结果应为:
1 a
1 b
2 c
3 null
4 null





...全文
59 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
--小F-- 2009-11-03
  • 打赏
  • 举报
回复
好象少了个括号
delete from
tb
where
exists
(
select
1
from
tb
where
name is null and id in(select id from tb group by id having count(1)>1))
--小F-- 2009-11-03
  • 打赏
  • 举报
回复
delete from 
tb
where
exists(select 1 from tb where name is null and id in(select id from tb group by id having count(1)>1)
-狙击手- 2009-11-03
  • 打赏
  • 举报
回复
Select *
from ta a where [name] is not null
union
select * from ta a
where not exists(select 1 from ta where id = a.id and [name] is not null)

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧