我试图列出所有销售超过20个单位的产品的所有ID

时间:2013-04-07 23:45:15

标签: sql oracle join sqlplus

这是我到目前为止所做的:

SELECT 
  Product_T.PRODUCTID, 
  Product_T.PRODUCTLINEID, 
  Product_T.PRODUCTDESCRIPTION, 
  Product_T.PRODUCTFINISH, 
  Product_T.PRODUCTSTANDARDPRICE, 
  Product_T.PRODUCTIONHAND, 
  OrderLine_T.ORDERLINEID, 
  OrderLine_TORDERID, 
  OrderLine_TPRODUCTID, 
  OrderLine_T.ORDEREDQUANTITY 
FROM 
  Product_T,
  OrderLine_T
WHERE 
  Product_T.ProductID = OrderLine_T.ProductID
AND 
  SUM(OrderLine_T.ORDEREDQUANTITY) > 20;

我收到此消息:

ORA-00934: group function is not allowed here 

有什么想法吗?任何帮助表示赞赏

1 个答案:

答案 0 :(得分:1)

改为使用HAVING

SELECT 
Product_T.PRODUCTID, 
Product_T.PRODUCTLINEID, 
Product_T.PRODUCTDESCRIPTION, 
Product_T.PRODUCTFINISH, 
Product_T.PRODUCTSTANDARDPRICE, 
Product_T.PRODUCTIONHAND, 
OrderLine_T.ORDERLINEID, 
OrderLine_TORDERID, 
OrderLine_TPRODUCTID, 
SUM(OrderLine_T.ORDEREDQUANTITY) OrderQty
FROM 
Product_T,
OrderLine_T
WHERE 
Product_T.ProductID = OrderLine_T.ProductID
GROUP BY
Product_T.PRODUCTID, 
Product_T.PRODUCTLINEID, 
Product_T.PRODUCTDESCRIPTION, 
Product_T.PRODUCTFINISH, 
Product_T.PRODUCTSTANDARDPRICE, 
Product_T.PRODUCTIONHAND, 
OrderLine_T.ORDERLINEID, 
OrderLine_TORDERID, 
OrderLine_TPRODUCTID
HAVING
SUM(OrderLine_T.ORDEREDQUANTITY) > 20;