2013년 12월 29일 일요일

4_3_행열변환

CREATE TABLE COPY_T (
  NO INT(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (NO)
) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

CALL USP_ADMIN_COPY_T_C(10000);

SELECT * FROM COPY_T

ALTER
    PROCEDURE `ecs`.`USP_ADMIN_COPY_T_C`()
    BEGIN
 DECLARE v_i INT DEFAULT 0;
 WHILE (v_i < 20) DO 
  INSERT INTO copy_t VALUES();
  SET v_i = v_i + 1; 
 END WHILE;



    END$$

DELIMITER ;


SELECT 
 F.reward_info_no
 , F.reward_type
 , F.reward_item_index
 , F.reward_count
 , F.desc_file_index
 , F.upt_time
 ,   F.content
FROM 
 EVENT__REWARD_INFO F,
 (SELECT DISTINCT 
  CASE no 
   WHEN 1 THEN 
    reward_info_no_0 
   WHEN 2 THEN 
    reward_info_no_1 
   ELSE 
    reward_info_no_2 
  END AS reward_info_no 
 FROM 
  (SELECT no
   , A.event_no
   , reward_info_no_0
   , reward_info_no_1 
   , reward_info_no_2 
  FROM 
   EVENT__LIST A
   , EVENT__DETAIL_INFO B
   ,(SELECT no 
    FROM 
     COPY_T 
    WHERE no < 4
     ) C 
  WHERE A.event_no = B.event_no 
  AND A.begin >= '2013-02-20' 
  AND A.end <= '2013-04-28'
  ) D
 ) E
WHERE E.reward_info_no  = F.reward_info_no