计算字段返回相同的值SQL

时间:2015-05-20 13:17:00

标签: oracle oracle11g

我遇到以下子查询的问题:

(select AVG(retail) 
 from STOCK 
 where category = 'TOYOTA' or category = 'HONDA') as AVERAGE_SALE_PRICE

整个查询:

select 
    d.name, s.category,(select AVG(retail) 
    where category = 'TOYOTA' or category = 'HONDA') as  AVERAGE_SALE_PRICE
from dealer d join stock s using (dealerID)

问题是这个计算字段为查询中的所有行返回相同的值,我知道我可能添加了一个GROUP BY,但我很困惑......

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

尝试此查询:

static
  

更新。这应该会给你想要的结果:

select AVG(retail) as AVERAGE_SALE_PRICE, category
from STOCK 
where category='TOYOTA' or category='HONDA'
group by category