gpt4 book ai didi

MySQL查询同一城市的不同表

转载 作者:行者123 更新时间:2023-11-29 21:07:57 35 4
gpt4 key购买 nike

表格:

Processor(_pid_, brand, clockSpeed, supplierCity)

Memory(_mid_, brand, capacity, supplierCity)

Harddrive(_hdid_, brand, capacity, RPM, supplierCity)

PC(_pcid_, _mid_, _pid_, _hdid_, model, price, cost)

我正在尝试构建一个查询:

Find's the PC model whose price is less than 1000 pounds and for which 
the memory and the processor are supplied from the same city

我当前的查询返回相同结果的多次重复:

SELECT pc.model FROM pc, memory, processor WHERE
memory.supplierCity=processor.supplierCity AND pc.price<1000;

enter image description here

最佳答案

SELECT  *
FROM pc
WHERE price < 1000
AND EXISTS
(
SELECT NULL
FROM processor p
JOIN memory m
USING (supplierCity)
WHERE (p._pid_, m._mid_) = (pc._pid_, pc._mid_)
)

关于MySQL查询同一城市的不同表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36652176/

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