mysql实现sql server 中rownumber

SELECT * FROM (
SELECT
   @row_number := CASE
WHEN  @Opportunity_Id = OpportunityId  THEN  @row_number + 1
ELSE  1
    END   AS  num,
   @Opportunity_Id := OpportunityId  AS  OpportunityId,
   ActualRevenue,
   DESCRIPTION,
   ModifiedOn
FROM
   OpportunityClose,( SELECT  @Opportunity_Id := '',@row_number := 0)  AS  t
ORDER BY  OpportunityId, ModifiedOn DESC
 ) re WHERE re.num=1

你可能感兴趣的:(SQL)