MySQL'partition by'子句

时间:2015-09-03 20:01:30

标签: mysql sql

我在partition子句中遇到错误。请帮我。错误是

 Select Model_Name,  
   Case Model_Subtype   
        When 'Weight' then 'Static'  
        When 'Linked Account' then 'Dynamic'  
        When 'Flexible' then 'Dynamic'  
       Else 'Not Defined'  
  End as Model_Type, Security_Name, Market_Value,Weight,  
  Case When Weight = 0 And Market_Value= 0 Then 0  
     When Weight  = 0 Then Cast(Market_Value/ nullif(SUM(market_Value)   
           OVER (Partition by Model_Name),0) AS Decimal (10,4))  
      When Weight !=0 Then Weight/100   
    Else Weight End as Target_Weight,  
         vehicle.Vehicle_Name  
    from   
  OFF_PRODUCT_MODEL model    
 Join OFF_PRODUCT_MODEL_TARGET target on target.Model_Id = model.Model_Id  
  Join OFF_PRODUCT_SECURITIES Sec on sec.Security_Id = target.Security_Id   
  left outer Join Offer_Back_End.tblStrategies Strategy on    Strategy.Vestmark_Sleeve_Code = model.Model_Name   
   left outer join Offer_Back_End.tblVehicles vehicle On vehicle.Vehicle_Id = strategy.Vehicle_ID
 Where (Strategy.Active_Strategy is null or Strategy.Active_Strategy = 1)  
  

错误] 1064 - 您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以获得正确的语法   在'(Partition by Model_Name)附近使用,0)AS十进制(10,4))                     当重量!= 0然后重量/'在第11行

2 个答案:

答案 0 :(得分:4)

嗯,OVER (Partition by Model_Name)是分析函数,MySQL很遗憾不支持并且没有它们,所以你得到了上述错误。

答案 1 :(得分:0)

MySQL不支持OVER()子句。通常,Window Functions不是MySQL的一部分。

您可以仿效它 - 请参考以下答案: