manhattes Posted October 22, 2015 Share Posted October 22, 2015 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 More sharing options...
manhattes Posted October 22, 2015 Author Share Posted October 22, 2015 I think I have to join the tables first. Link to comment https://forums.phpfreaks.com/topic/298782-using-lag/#findComment-1524080 Share on other sites More sharing options...
mac_gyver Posted October 23, 2015 Share Posted October 23, 2015 based on the error message, you are using mysql. the lag and over functions don't exist in mysql. they are ms sql features. Link to comment https://forums.phpfreaks.com/topic/298782-using-lag/#findComment-1524113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.