24 February 2018

netIncome

My solution:
CREATE PROCEDURE 
  netIncome() 
BEGIN 
  SELECT   YEAR(   date)                                                AS year, 
           QUARTER(date)                                                AS quarter, 
           SUM(CONVERT(profit, SIGNED INT) - CONVERT(loss, SIGNED INT)) AS net_profit 
  FROM     accounting 
  GROUP BY year, 
           quarter 
  ORDER BY date; 

END

Note:
profit: BIGINT UNSIGNED and
loss: BIGINT UNSIGNED
need to be converted to SIGNED INT.