注册 登录
编程论坛 Oracle论坛

oracle的视图题,求高手帮忙啊!!

inki亦 发布于 2010-11-23 19:03, 610 次点击
修改视图vu_p1,查询每个商品的销售额大于50的记录,显示字段产品名称、销售额,并查看。
这个问题的前一题是
创建一个视图vu_p1,查询每个商品的销售额,显示字段为商品名称、销售额,并查看。
我已经做出来了,答案也是正确的
create or replace view vu_p1
as
select product.product_name,sum(price*sale_num) as sale_money
from sale_detail,sale,product
where sale_detail.sale_id=sale.sale_id
and sale_detail.product_id=product.product_id
group by product.product_name;

但是题目上的这个要“查询每个商品的销售额大于50的记录”就是要查的是计算出的结果的一个量来做视图,不晓得怎么弄了,如果在where的条件里面加sale_money>50它又会报错,好像是说sale_money是select里面计算的不可以查询,望高手予以解答,看这个题应该怎么做出来啊?!
谢谢!!!
2 回复
#2
哈狄斯2010-11-29 16:45
可以直接写 sum(price*sale_num) > 50 因为sale_money 是别名 不可以直接用 ,除非order by 后面可以接,其他都不行!
#3
路過2011-01-25 17:38
create or replace view vu_p1
as
select product.product_name,sum(price*sale_num) as sale_money
from sale_detail,sale,product
where sale_detail.sale_id=sale.sale_id
and sale_detail.product_id=product.product_id
having sum(price*sale_num) > 50
group by product.product_name;
1