/*
análisis limesurvey, como se construyen o codifican los nombres de columnas
#ingeniería inversa
#mysql
#query
#nameCol
*/
SELECT
a.qid,
a.title,
a.parent_qid,
#level1
if(a.parent_qid=0 AND (a.type = 'L' or a.type = 'T'),
a.title , if(a.parent_qid>0 AND (a.type = 'F' or a.type = 'T' ) AND
(select xx.type from lce_questions xx where xx.qid = a.parent_qid) = 'F'
,
#level2
(SELECT CONCAT(b.title,'')
from lce_questions b
WHERE b.qid = a.parent_qid
)
,
#level3
if( (select xx.type from lce_questions xx where xx.qid = a.parent_qid) = ';' AND a.question!='' ,
(SELECT CONCAT(b.title,'')
from lce_questions b
WHERE b.qid = a.parent_qid #level3
)
,'--')
)
) as result
,
if(a.parent_qid=0 AND (a.type = 'L' or a.type = 'T'),
CONCAT(a.sid,'X',a.gid,'X', a.qid) ,
if(a.parent_qid>0 AND (a.type = 'F' or a.type = 'T' ) AND
(select xx.type from lce_questions xx where xx.qid = a.parent_qid) = 'F'
,
(SELECT CONCAT(a.sid,'X',a.gid,'X', a.parent_qid,a.title)
from lce_questions b
WHERE b.qid = a.parent_qid
) ,
if( (select xx.type from lce_questions xx where xx.qid = a.parent_qid) = ';' AND a.question!='' ,
(SELECT CONCAT(a.sid,'X',a.gid,'X', a.parent_qid,a.title,'_SQ001')
from lce_questions b
WHERE b.qid = a.parent_qid
) ,'--')
)
) as colName
FROM
lce_questions a
WHERE
a.sid = 'YOUR SID CODE'
HAVING result !='--'
ORDER BY a.qid, a.question_order