在子句中使用子查询

时间:2017-06-09 10:25:00

标签: hive hadoop2

我是hive的新手,请帮助我,我有一个表名prac,我需要 找到比产品鼠标更多的利润(价格 - 成本)的产品。我已经尝试了以下查询,但它无法正常工作。

select product_name,price-cost 
from   prac 
where  price-cost > (select price-cost from prac where product_name='mouse')

我的数据是

id,product_name,product_type,price,cost,date
100,maker,stationary,25,22,2008-01-15
101,mouse,computer,450,350,2009-04-16
102,white  board,stationary,450,375,2010-06-25
103,sony viao,computer,35000,42000,2010-09-21

1 个答案:

答案 0 :(得分:0)

我得到了答案

select a.*,a.price-a.cost profit
from prac a 
join (select price-cost p from prac where p_name='Maker') b 
where a.price-a.cost>b.p;
相关问题