[Solved] Create different result set using one result set [closed]


To use a resultset in a query condition for a set of queries you need a cursor.

Please check out basics of cursor usage here and in the docs

DELIMITER $$

CREATE PROCEDURE group_results_by_date 
BEGIN

 DECLARE v_finished INTEGER DEFAULT 0;
 DECLARE cdate DATE DEFAULT "2015-01-01";

 -- declare cursor for getting list of dates
 DEClARE date_cursor CURSOR FOR 
    SELECT DISTINCT (date) FROM yourtable;

 -- declare NOT FOUND handler
 DECLARE CONTINUE HANDLER 
        FOR NOT FOUND SET v_finished = 1;

 OPEN date_cursor;

 get_content: LOOP

 FETCH date_cursor INTO cdate;

 IF v_finished = 1 THEN 
 LEAVE get_content;
 END IF;

 -- Select query for different dates
 Select count, date, content from yourtable where date = cdate;

 END LOOP get_content;

 CLOSE date_cursor;

END$$

DELIMITER ;

You can call this procedure by

CALL group_results_by_date();

solved Create different result set using one result set [closed]