Here is my current table
╔══════╦═══╦═══╦═══╦═════╦════╗
║ YEAR ║ A ║ B ║ C ║ ... ║ ZZ ║
╠══════╬═══╬═══╬═══╬═════╬════╣
║ 1995 ║ 1 ║ 0 ║ 1 ║ ... ║ 1 ║
║ 1996 ║ 1 ║ 1 ║ 0 ║ ... ║ 0 ║
╚══════╩═══╩═══╩═══╩═════╩════╝
And the table contains around 1000 columns. Now i need to write a code to rotate this table into a more sensible table where i represent values which are denoted as 1. So the resulting table should be like
╔══════╦════════╦═══════╗
║ YEAR ║ COLUMN ║ VALUE ║
╠══════╬════════╬═══════╣
║ 1995 ║ A ║ 1 ║
║ 1995 ║ C ║ 1 ║
║ 1995 ║ ZZ ║ 1 ║
║ 1996 ║ A ║ 1 ║
║ 1996 ║ B ║ 1 ║
╚══════╩════════╩═══════╝
So by googling bit i started creating a SQL like follows
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
DECLARE v_du **???** DEFAULT "";
DEClARE du_cursor CURSOR FOR SELECT * FROM date_usage;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1;
OPEN du_cursor;
get_du: LOOP
FETCH du_cursor INTO v_du;
IF v_finished = 1 THEN
LEAVE get_du;
END IF;
SHOW v_du; <<---
END LOOP get_du;
CLOSE du_cursor;
END
But the problem is i'm not sure how to specify the v_du to be a column and I'm not sure how I'm going to read the column names. And help would be appreciated.
Thankx