查询结果不会崩溃

时间:2017-03-03 15:45:48

标签: sql oracle

我可以得到一些帮助。

查询如下:

SELECT  
       SUBSTR(house.nr,1,3), SUM(road.quantity),
       COUNT(people.name),  goods.price*sum(road.quantity) /goods.quantity          

FROM       home, road, house, goods, people

WHERE      home.hoid = road.roid
           AND home.hrid = house.nrid
           AND road.gdsid = goods.goodsid
           AND goods.nmid = people.nameid

GROUP BY   SUBSTR(nr,1,3), people.name, goods.price, road.quantity, goods.quantity

ORDER BY   SUBSTR(nr,1,3) 

This is what I get

This is what I want

先谢谢。

1 个答案:

答案 0 :(得分:0)

您按名称,价格和数量进行分组,因此每个值的结果将包含一行。而是通过第一列选择聚合和分组:

SELECT  
   SUBSTR(house.nr,1,3), SUM(road.quantity), COUNT(people.name),
   SUM(goods.price*sum(road.quantity) /goods.quantity) AS price
...
GROUP BY SUBSTR(house.nr,1,3)