这样的 查询 能 作 吗

shenweijuan 2002-11-18 01:03:01
我想实现这样的功能,在我的数据库表单中有这样两个列
object_id (int )(非唯一的) object_state (bit) (1,0)
我想返回所有的object_id 条件是每个object_id 的object_state 都是1,
这样的查询好做吗,还是我的数据库在设计上就存在不合理。
...全文
22 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenweijuan 2002-11-18
  • 打赏
  • 举报
回复
非常感谢 sky_blue , 我测试过了,是可以这样做的谢谢!
蓝天 2002-11-18
  • 打赏
  • 举报
回复
select objectID from yourtable t1 where not exists (select 1 from yourtable t2 where t1. objectID = t2.objectID and t2.objectstate <> 1)
蓝天 2002-11-18
  • 打赏
  • 举报
回复
select objectID from yourtable t1 where not exists select 1 from yourtable t2 where t1. objectID = t2.objectID and t2.objectstate <> 1
shenweijuan 2002-11-18
  • 打赏
  • 举报
回复
是我说的不明白还是什么,要是按上面所说的,我的问题就显得很幼稚了
是这样的
objectID otherthing objectstate
1000 that 1
1000 this 1
2000 those 1
2000 thesee 1
2000 nothing 0
。。。
在这种情况下我需要返回一个objectID=1000
蓝天 2002-11-18
  • 打赏
  • 举报
回复
object_id 是MSSQL的关键字,你还是换个名字吧

另外查询你难道是要

select object_id from yourtable where object_state =1

?
CrazyFor 2002-11-18
  • 打赏
  • 举报
回复
select object_id from yourtable where object_stat=1

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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