Teradata到mysql转换 - 限定和排名

时间:2018-04-26 08:36:45

标签: mysql sql teradata

我有一个teradata代码,如下所示:

select *
from date_dim a
left join 
(select incident_number,incident_type,submit_date from itamr qualify RANK() OVER (PARTITION BY incident_number ORDER BY last_modified_date DESC) = 1)b
on a.Clndr_Dt = b.submit_date
and b.incident_type = 'Request';

我需要将限定等级和分区转换为mysql。 我尝试分组而不是分区。 有人可以帮我解决如何在mysql中转换qualify和排名吗?

1 个答案:

答案 0 :(得分:1)

QUALIFY是一个teradata专有关键字。 Howover RANK功能适用于任何Relational DB。您可以使用子查询替换QUALIFY语句,如下所示:

 select *
from date_dim a
left join 
(
select * from 
(select incident_number,incident_type,submit_date ,
RANK() OVER (PARTITION BY incident_number ORDER BY last_modified_date DESC) rn
from itamr ) sub where rn = 1 ) b
on a.Clndr_Dt = b.submit_date
and b.incident_type = 'Request';