对于已多次销售商品的供应商的SQL查询

时间:2010-11-06 20:01:31

标签: sql

我需要以下查询的帮助...显示多次向我们出售商品的供应商的名称。列出供应商,项目和订购的次数。假设供应商在12月1日的12月1日和12月12日的第240项中卖出了第8项中的8项;这计为项目240的两个总订单(不是20)。表格是......

employee (empid, firstname, middleinitial, lastname, address)
parts (partnum, description)
payments (checknum, checkdate, vendorid, ponum, accountnum, amount)
poitems (ponum, partnum, quantity, unitprice)
purchaseorder (ponum, podate, vendorid, empid, amount)
vendor (vendorid, name, address, phone, tin)

1 个答案:

答案 0 :(得分:1)

SELECT vendor.name, partnum, COUNT (DISTINCT ponum) AS times_ordered
FROM purchaseorder
JOIN vendor USING (vendorid)
JOIN poitems USING (ponum)
GROUP BY vendorid, partnum
HAVING times_ordered > 1