-1

我需要帮助来找到以下练习的解决方案:我有这张表:

maker   model   type
E   2010    laptop
E   1013    pc
E   1012    pc
D   2007    laptop
D   1011    pc
D   1010    pc
D   1009    pc
C   3006    printer
C   3003    printer

而且我需要以至少 700 的速度找到至少 2 台不同计算机 (Pc) 的制造商。我尝试了几个查询但没有。你能告诉我如何写这个查询是真的吗?

速度列在另一个名为 PC 的表中,我们有模型、速度、价格等我尝试了一些类似这样的查询:

select maker from product p
join pc pc on pc.model=p.model
where pc.speed>700
group by maker
having count(distinct p.model)>=2;

但它不能正常工作,我不知道该怎么办!如果您能帮助我,我将更加感激!

4

2 回答 2

2

为了退货,Manufacturers of at least 2 different computers您需要确保您计算的型号不同。否则,您可能会计算相同型号的两倍(除非 [制造商,型号] 对中存在唯一性)

select maker from table
where type = 'pc' and model >= 700      -- Should be Speed in this line?
group by maker
having count(distinct model) >= 2
于 2013-10-29T16:26:35.230 回答
1

分组maker并相应地过滤结果:

SELECT   maker
FROM     my_table
WHERE    type = 'pc' AND model >= 700
GROUP BY maker
HAVING   COUNT(*) >= 2

sqlfiddle上查看。

于 2013-10-29T16:17:54.437 回答