关于查找的问题

kinvb 2003-12-23 03:36:59
在一个数据表A
模号 工时
6364 0.050
6565 0.045

另一个表B
姓名 模号 良品数
小飞 6364 1000
小胡 6565 900
小黑 6364 900
. . .
. . .
. . .
请问表B的每个人都做过存在在表A的模号的产品有那些
...全文
81 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
devilwind 2003-12-23
  • 打赏
  • 举报
回复
select distinct 姓名 into #tmp from B

select count(*) from #tmp

select c.模号 from (select a.模号,count(a.模号) as b from B right join A on B.模号=A.模号 group by a.模号) c
where c.b=(select count(*) from #tmp)
xzx760815 2003-12-23
  • 打赏
  • 举报
回复
首先求表2中人數用
select count(*) from (select 姓名 from 表2 group by 姓名) a
然后 表1與表2關聯并按模號分組,找出關聯后次數等于人數的模塊。
即﹕
select a.模號 from 表1 a inner join 表2 b on a.模號=b.模號 group by a.模號
having count(*)=(select count(*) from (select 姓名 from 表2 group by 姓名) a )


victorycyz 2003-12-23
  • 打赏
  • 举报
回复
select 姓名
from
( select distinct b.姓名,b.模号
from
( select distinct 姓名
from tableB
) b left join tableA a on a.模号=b.模号
) c
group by 姓名
having count(*)=1
Rotaxe 2003-12-23
  • 打赏
  • 举报
回复
select 模号 from a where not exists( select * from b b1 where a.模号=b.模号 and not exists( select * from b2 where b2.姓名=b1姓名 and a.模号=b2.模号))
kinvb 2003-12-23
  • 打赏
  • 举报
回复
在一个数据表A
模号 工时
|--6364 0.050
| 6565 0.045
|-----------------------------------我的意思是查找出像表A对应表B的有所有模号
| 并且表A的模号都存在在表B中的每个人做的良品数
| 至少有一次的模号.
| 另一个表B
| 姓名 模号 良品数
|- 小飞 6364 1000
| 小胡 6565 900
|- 小黑 6364 900
. . .
. . .
. . .
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
select * from B as a
where
(select count(*) from A group by 模号)
=
(select count(*) from (select distinct 模号 from B where 姓名=a.姓名) b)
j9988 2003-12-23
  • 打赏
  • 举报
回复
select 模号
from 表A A
where not exists(select 1 from
(select * from (
(select distinct 姓名 from 表B) B,(select 模号 from 表A ) C
) D
left join 表B E
on D.姓名=E.姓名 and D.模号=E.模号
where D.模号=A.模号 and E.模号 is not null)
DigJim 2003-12-23
  • 打赏
  • 举报
回复
不知道怎麽問的?
看不懂
kinvb 2003-12-23
  • 打赏
  • 举报
回复
我的意思是:查询表A里有那些模号是表B的每个人都有相关记录的
tomhuang 2003-12-23
  • 打赏
  • 举报
回复
不是很清楚你的意思,能再说清楚些吗?

34,590

社区成员

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

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