hadoop - how do retrieve specific row in Hive? -
i have dataset looks this:
--------------------------- cust | cost | cat | name --------------------------- 1 | 2.5 | apple | pklady --------------------------- 1 | 3.5 | apple | greengr --------------------------- 1 | 1.2 | pear | yellopear ---------------------------- 1 | 4.5 | pear | greenpear -------------------------------
my hive query should compare cheapest price of each item customer bought. want 2.5 , 1.2 1 row difference. since new hive don't how ignore else until reach next category of item while still kept cheapest price in previous category.
you create subquery containing minimum cost each customer, , join original table:
select mytable.*, mincost.mincost, cost - mincost costdifference mytable inner join (select cust, min(cost) mincost mytable group cust) mincost on mytable.cust = mincost.cust
i created interactive sqlfiddle example using mysql, should work fine in hive.
Comments
Post a Comment