Hive 仅针对来自不同日期的一条记录的配置单元查询帮助

Hive 仅针对来自不同日期的一条记录的配置单元查询帮助,hive,Hive,对于一个项目,我只需要选择一天的一条记录,即星期天,因为在所有日期allocwgt的值都是相同的 一个项目可以有多个记录,每天为不同的日期,但我只需要7条记录。。每天1次记录 Store number allocwgt item date day 88006 0.14 40000349094 1/6/2013 Sunday 10374 0.14 40000349094 1/6/2013 Sunday 88010 0.14 4000

对于一个项目,我只需要选择一天的一条记录,即星期天,因为在所有日期allocwgt的值都是相同的

一个项目可以有多个记录,每天为不同的日期,但我只需要7条记录。。每天1次记录

Store number    allocwgt    item    date    day
88006   0.14    40000349094 1/6/2013    Sunday
10374   0.14    40000349094 1/6/2013    Sunday
88010   0.14    40000349094 3/19/2017   Sunday
9388    0   40000349094 1/7/2013    Monday
9300    0   40000349094 3/20/2017   Monday
9300    0   40000349094 3/27/2017   Monday
1139    0   40000349094 3/16/2015   Monday

使用
行号()。下面的查询将为每个
项目
只选择一条记录,其中至少有
门店号
。在
over()
中写入正确的
order by
,以更改此行为,或者如果需要每个项目的任何
order by
记录,只需删除
order by
,并且
date
我将
date
列替换为
store\u date
,因为
date
hive
中的保留字

i.e sunday, monday, tuesday as on..
 Note : if record selected is of most updated will be good  
Can someone help me in making this in hive query.

Expected output should be:

Store number    allocwgt    item            date            day 
88006           0.14        40000349094     2017-03-19      Sunday
09300           0.00        40000349094     2017-03-27      Monday
select Store_number, allocwgt, item, store_date, day
from
(
select Store_number, allocwgt, item, store_date, day, 
       row_number() over(partition by item, store_date order by store_number) rn
from table_name
) s
where rn=1
Thanks Query is giving result as expected but I had a confusion that allocwgt value will be same but it could be different which I found.

Now when I ran below query :   

 create table temp_cso_2 as 
select *
from
(
select b.loc,
 a.allocwgt, 
 b.item,
 date_add('1970-01-01',cast ((a.Eff/1440)as int)) as date_from_minutes,
 date_format(date_add('1970-01-01',cast ((a.Eff/1440)as int)),'EEEE') as day_of_date, 
 row_number() over(partition by item, date_add('1970-01-01',cast ((a.Eff/1440)as int)) order by b.loc) rn
from scm.CALDATA a left outer join scm.SKUDEMANDPARAM b
on a.cal = b.alloccal
where a.repeat = 0 and b.run_date= to_date('2017-03-02' ) and b.item between 40000000000 and 40000999999
) s
where rn=1      

this query gives me below result  

    ------------------------------+-----------------+----------------------+------------------+-------------------------------+-------------------------+----------------+--+
    | temp_cso_2.loc  | temp_cso_2.allocwgt  | temp_cso_2.item  | temp_cso_2.date_from_minutes  | temp_cso_2.day_of_date  | temp_cso_2.rn  |
    +-----------------+----------------------+------------------+-------------------------------+-------------------------+----------------+--+
    | 00074           | 0.15                 | 40000110552      | 2013-01-10                    | Thursday                | 1              |
    | 00074           | 0.17                 | 40000110552      | 2013-01-11                    | Friday                  | 1              |
    | 00074           | 0.17                 | 40000110552      | 2013-01-12                    | Saturday                | 1              |
    | 00074           | 0.12                 | 40000110552      | 2013-01-06                    | Sunday                  | 1              |
    | 00074           | 0.12                 | 40000110552      | 2013-01-07                    | Monday                  | 1              |
    | 00074           | 0.13                 | 40000110552      | 2013-01-08                    | Tuesday                 | 1              |
    | 00074           | 0.14                 | 40000110552      | 2013-01-09                    | Wednesday               | 1              |
    | 00074           | 0.0                  | 40000110552      | 2018-04-24                    | Tuesday                 | 1              |
    +-----------------+----------------------+------------------+-------------------------------+-------------------------+----------------+--+

So problem is in tuesday record. I got two records because allocwgt are differnt so what should I do so that I get only one latest date record. Also something to increase perfromance of this query ?  Please help