Jump to content

using LAG


manhattes

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
https://forums.phpfreaks.com/topic/298782-using-lag/
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • 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.