用sql语句怎麼找出供应商中供货量最多的供应商,

来源:百度知道 编辑:UC知道 时间:2024/09/24 22:54:45
在NorthWind数据库中用sql语句怎麼找出供应商中供货量最多的供应商.
第一 问:查出各供应商的供应商品的数量
第二 问:找出供货商中供货最多的供应商
知道的都来写下.
在Suppliers表和Products表中查找.
2个表结勾可以查看NorthWind数据库,

第一 问:查出各供应商的供应商品的数量
答:
select Suppliers.SupplierID as '供应商ID',count(*) as '供应商品的数量' from products inner join suppliers on products.SupplierID = Suppliers.SupplierID group by Suppliers.SupplierID

第二 问
答:
select top 1 Suppliers.SupplierID as '供应商ID',count(*) as 'xxx' from products inner join suppliers on products.SupplierID = Suppliers.SupplierID group by Suppliers.SupplierID order by xxx desc

我测试过,能解决你所提的问题。

Select 加上数据库中的供应商供应商品的数量 的列名,
供货商中供货最多的供应商 的列名
from 数据库名。