-2

I am getting error in the partition clause. Please help me. The error is

 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)  

Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(Partition by Model_Name),0) AS Decimal (10,4)) When Weight !=0 Then Weight/' at line 11

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
user60811
  • 1
  • 1
  • 3
  • mysql doesn't support partitioning like that, and we are not a code translation service. – Marc B Sep 03 '15 at 20:04
  • MySQL does not support the `OVER()` clause. – Bacon Bits Sep 03 '15 at 20:04
  • I don't think the question is a duplicate because the OP is asking for the *correct* syntax to perform this operation. – Gordon Linoff Sep 03 '15 at 20:09
  • For those coming to this question now, [MySQL added `OVER()` window function with the 8.0 release](https://dev.mysql.com/blog-archive/mysql-8-0-2-introducing-window-functions/). – Patrick M Sep 01 '22 at 20:25

2 Answers2

3

Umm, OVER (Partition by Model_Name) is analytical function which MySQL unfortunately doesn't support and don't have them and so you are getting the said error.

Rahul
  • 76,197
  • 13
  • 71
  • 125
  • Hi Rahul, Thank you for your quick reply. Can you please tell me how do I convert Over(Partition by Model_Name ) clause in MySQL? I appreciate for your help. – user60811 Sep 04 '15 at 13:47
0

MySQL does not support OVER() clause. In general Window Functions are not part of MySQL.

You can however emulate it - please refer to the following answer:

Community
  • 1
  • 1
Michał Szkudlarek
  • 1,443
  • 1
  • 21
  • 35