请教一个SQL语句

feng1214 2008-03-01 11:33:45
有个表字段为
GroupID 组编号,UserID 用户编号


怎样查询用户没有加入的组
...全文
52 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2008-03-01
  • 打赏
  • 举报
回复
有点像....
dawugui 2008-03-01
  • 打赏
  • 举报
回复
有个表字段为
GroupID 组编号,UserID 用户编号


怎样查询用户没有加入的组
----------------
declare @usrid as int
set @usrid = 某值

select distinct GroupID from tb where GroupID not in (select GroupID from tb where UserID = @userid)
-狙击手- 2008-03-01
  • 打赏
  • 举报
回复
???
-狙击手- 2008-03-01
  • 打赏
  • 举报
回复
select distinct groupid
from Ta a
where not exists(select 1 from ta where userid = a.userid and userid = @userid )
中国风 2008-03-01
  • 打赏
  • 举报
回复
楼主有点在倒分哟
中国风 2008-03-01
  • 打赏
  • 举报
回复

select distinct GroupID from T a where not exists(select 1 from T where GroupID=a.GroupID and UserID='001')


select GroupID from T a where GroupID not in(select GroupID from T where UserID='001')
feng1214 2008-03-01
  • 打赏
  • 举报
回复
谢谢
JiangHongTao 2008-03-01
  • 打赏
  • 举报
回复
select distinct groupid from tb
where groupid not in(select groupid from tb where userid = @id)
JiangHongTao 2008-03-01
  • 打赏
  • 举报
回复
select groupid from tb
where groupid not in(select groupid from tb where userid = @id)

22,209

社区成员

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

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