mysql row_number over(partitioned xx order by aa desc)
972 ワード
select * from(
select @rownum:=@rownum+1 ,if(@uid = t.item_name and @cid = t.price_date ,
@rank := @rank + 1,
@rank := 1) as rank,
t.*,
@uid := t.item_name,
@cid := t.price_date
from (select@rownum:=0, @uid := null, @cid := null, @ccc := null, @rank := 0) r,
(select upper(item_name) as item_name , price_date, crawl_time,
' ' AS ITEM_TYPE ,upper(item_name) AS ITEM_TYPE2,area
,market
,model
,price
,case when upper(item_name) = 'PP' then (cast(price as int)*1.09) else cast(price as int) end tax_price
from DM_.DM_KAFKA
where upper(item_name) ='ABS' AND price_date ='2020-3-20'
group by upper(item_name), price_date,crawl_time --
order by crawl_time DESC -- , ,
) t ) g
order by rank ASC