gpt4 book ai didi

至少 SQL 数

转载 作者:行者123 更新时间:2023-12-02 05:36:25 26 4
gpt4 key购买 nike

我需要找到生产至少三种不同型号电脑的制造商。结果集:制造商、型号数量。

我的 table 是产品(制造商、型号、类型)PC(代码、型号、速度、内存、高清、CD、价格)

我现在已经这样做了

SELECT Product.maker, PC.model 
FROM PC, Product
WHERE Product.model=PC.model

最佳答案

PCcontains only the computers having been produced and it may be missing some existing models not yet produced :

The table "Product" includes information about the maker, model number, and type ('PC', 'Laptop', or 'Printer'). It is assumed that model numbers in the Product table are unique for all the makers and product types. Each PC uniquely specifying by a code in the table "PC" is characterized by model (foreign key referencing to Product table), speed (of the processor in MHz), total amount of RAM - ram (in Mb), hard disk drive capacity - hd (in Gb), CD ROM speed - cd (for example, '4x'), and the price.

所有模型都包含在Product 表中。

事实证明,Product 表具有产品类型的标志:type

因此,查询实际上甚至不需要联接:

select maker, count(model)
from Product
where type = 'PC'
group by maker
having count(model) >= 3

关于至少 SQL 数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9005146/

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