我有以下列和数据
id, FN,LN,address
1,p,k,bangalore
2,M,K,Chennai
输出应如下所示
ID,NAME,Names,ADdress
1, FN,P,Bangalore
1,LN,K,Bangalore
2,FN,M,Chennai
2,LN,K,Chennai
任何人都可以帮助我如何在SQL-MYSQL中获得以上输出
答案 0 :(得分:0)
执行UNION ALL
,其中一行SELECT
表示fn行,一行SELECT
表示行:
select id, 'FN' as name, fn as names, address from tablename
UNION ALL
select id, 'LN' as name, ln as names, address from tablename
order by id, name -- if required
可选ORDER BY
,保留或删除它,具体取决于预期的顺序。