text: Q:
  
  Get sum of two columns and save it to variable
  
  In my MySQL, I have field ID, price, and date field (timestamp).
  I want to, at end of the month, calculate total cost for that month and save it to variable $monthjuly.
  SELECT SUM(price) FROM app WHERE YEAR(datum) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH) AND MONTH(datum) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)"
  
  I tried via this command to output results, but I am not getting any result with this metod.
  Where is my mistake here?
  
  A:
  
  Edit:
  You are doing a SUM with no grouping of data.  Whenever you aggregate data you need to have a grouping.  In this case we group by year and month.
  Demo - http://sqlfiddle.com/#!9/d952a3/1
  SELECT SUM(price), year(datum), month(datum)
  FROM app
  WHERE
      YEAR(datum) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)
      AND MONTH(datum) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH)
  GROUP BY YEAR(datum), MONTH(datum)
  
  