mysql row_number over(partitioned xx order by aa desc)

 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

 

你可能感兴趣的:(mysql)