[求助] 请教一句简单SQL

realmud 2005-08-15 02:57:12
表格如下:
ColumnA ColumnB
a 1
a 0
b 1
c 0
...

当一条记录ColumnB 为1时,则可能存在另一条ColumnA相同,但是ColumnB 为0的纪录。
求一SQL, 能返回出所有ColumnB 为1时,相对应ColumnB为0的记录的ColumnA。
...全文
113 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
waterfirer 2005-08-15
  • 打赏
  • 举报
回复
IsNull换成nvl
realmud 2005-08-15
  • 打赏
  • 举报
回复
为何显示

ERROR at line 1:
ORA-00933: SQL command not properly ended

我用的是Oracle9
jzdmyjzd 2005-08-15
  • 打赏
  • 举报
回复

select * from tbl as a where ColumnB=1 and
(select IsNull(Count(*),0) from tbl where ColumnB = 0 and ColumnA=a.ColumnA) = 1
Order By ColumnA Asc

当有多条ColumnB 为0的纪录,对应一个ColumnA时,建议采用WangZWang(阿来) 的方法。
vivianfdlpw 2005-08-15
  • 打赏
  • 举报
回复
select * from 表 t
where exists(select 1 from 表 where columnA=t.columnA and columnB+t.columnB=1)
WangZWang 2005-08-15
  • 打赏
  • 举报
回复
select * from tbl as a where ColumnB=1 and exists
(select * from tbl where ColumnB=0 and ColumnA=a.ColumnA)
realmud 2005-08-15
  • 打赏
  • 举报
回复
如果没有相应COlumnB为0的记录,则不显示

34,576

社区成员

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

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