gpt4 book ai didi

mysql - 我正在尝试执行 mysql 查询以获取只供应红色部分的供应商?

转载 作者:行者123 更新时间:2023-11-29 00:23:56 27 4
gpt4 key购买 nike

这里是mysql查询

select distinct C.sid
from Catalog C
where not exists
( select * from Parts P where P.pid = C.pid and P.color != 'red');

但它返回供应红色零件的供应商而不仅仅是红色零件?以及如何改变它的想法

我有3张 table

Suppliers(sid: integer, sname: string, address: string) 
Parts(pid: integer, pname: string, color: string)
Catalog(sid: integer, pid: integer, cost: real)

任何帮助将不胜感激,谢谢

最佳答案

select
sid
from
suppliers s
where
exists (
select
'x'
from
catalog c
inner join
parts p
on c.pid = p.pid
where
s.sid = c.sid and
p.color = 'red'
) and
not exists (
select
'x'
from
catalog c
inner join
parts p
on c.pid = p.pid
where
s.sid = c.sid and
p.color != 'red'
)

关于mysql - 我正在尝试执行 mysql 查询以获取只供应红色部分的供应商?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19942240/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com