24 February 2018

alarmClocks

My solution:
CREATE PROCEDURE alarmClocks() 
BEGIN 
  DROP TABLE IF EXISTS calendarWeek; 

  CREATE TABLE calendarWeek 
    ( 
       `number` INT 
    ); 

  SET @s = 0; 

  loopLabel: 
LOOP 
    INSERT INTO calendarWeek 
                (`number`) 
    VALUES      (@s); 
    SET @s = @s + 1; 
    IF @s <= 53 THEN 
      ITERATE loopLabel; 
    END IF; 
    LEAVE loopLabel; 
  END LOOP loopLabel; 

  SELECT alarm_date 
  FROM   (SELECT DATE_ADD(input_date, INTERVAL (7 * number) DAY) AS alarm_date 
          FROM   userInput, 
                 calendarWeek) AS t, 
         userInput 
  WHERE  YEAR(alarm_date) = YEAR(input_date); 
END