php - How to calculate difference between values coming from the same row in mysql -


I am trying to calculate the difference in the value list coming from a database. I would like to use it PHP or mysql, but I do not know how to proceed. I have a table named Player_coreres, it has scored one of the lines.

E.g. Of

  pl_date pl_scores 03/11/2014 18 2014/02/11 15 2014/01/11 10  

matches I played in goal different dates For example, you want to echo the difference between runs scored

  For example:. Pl_date pl_scores diff 03/11/2014 18 + 3 02/11/2014 15 +5 01/11/2014 10 No difference  

How do I get the desired result?

You seem to want to compare a score against the score on a previous line.

Perhaps the most simple, the sub-query that is used to maximum pl_date is that the current row is less than pl_date, then return the results of inquiry against the sub player_scores table join to get information for each date: -

  ps1.pl_date, ps1.pl_scores, IF (ps2.pl_date ps1.pl_scores = ps1.pl_scores, 'no diff ', ps1.pl_scores zero or - ps1.pl_scores) diff (Select as ps1.pl_date, MAX (ps2.pl_date) prev_date player_scores from ps1 LEFT OUTER player_scores ps2 oN ps1.pl_date & gt; ps2.pl_date GROUP BY ps1.pl_date) sub 0 Inner Plear_scots Join sub0.prev_date = ps2.pl_date player_scores PS2 on ps1 Join the sub0.pl_date = ps1.pl_date LEFT OUTER  
< p> this (for example, it may be other ways, ordered one are using variables to work through the Deputy results Quer with values ​​stored in the variable y, the last line Compare each line)


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -