Jump to content

using LAG


manhattes
Go to solution Solved by mac_gyver,

Recommended Posts

I am trying to calculate the difference in the previous row using the following query.

 

$query2 = "select * from " . $wsym .",CleanedCalendar where '" . $wsym ."' = CleanedCalendar.Symbol AND " . $wsym .".Close - LAG(" . $wsym .".Close) OVER (ORDER BY " . $wsym .".Date) AS difference FROM " . $wsym .""; 

 

I am trying to open two tables and populate a new field called difference.

The query works until I add the AND portion of the statement. Is my formatting wrong or am I not allowed to do this?

 

Print:

select * from AMDA,CleanedCalendar where 'AMDA' = CleanedCalendar.Symbol AND AMDA.Close - LAG(AMDA.Close) OVER (ORDER BY AMDA.Date) AS difference FROM AMDA

 

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 'OVER (ORDER BY AMDA.Date) AS difference FROM AMDA' at line 1

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.