基于具有不同值的相同列名创build列

我有一张桌子:

元表

如上图所示,还有许多其他的meta_appl_id。

现在我想运行一个SQL查询,以便根据“meta_value”的值创build列。 我试过了:

SELECT * , if (`meta_value` = 'physically challenged' , 'yes', '') as PH, if (`meta_value` = 'kannada medium' , 'yes', '') as Kannada, if (`meta_value` = 'rural' , 'yes', '') as rural, if (`meta_value` = 'woman' , 'yes', '') as woman FROM `applicant_meta` WHERE `meta_value` = 'physically challenged' or `meta_value` = 'woman' group by meta_appl_id; 

但不能得到所需的输出,只有一列值如图所示:

产量

其实在行meta_appl_id 59它必须显示Ph – 是的,农村 – 是和女人是的,但它只在女人(因为它是最后一个如果在查询语句)显示。

 SELECT meta_appl_id, if(PH= 0, 'no', 'yes'), if(WOMAN= 0, 'no', 'yes') FROM ( SELECT meta_appl_id , (select count(1) FROM applicant_meta as innertab where UPPER(innertab.meta_appl_id) = UPPER(aa.meta_appl_id) and UPPER(meta_value)=UPPER('physically challenged')) as PH , (select count(1) FROM applicant_meta as innertab where innertab.meta_appl_id = aa.meta_appl_id and UPPER(meta_value)='WOMAN') as WOMAN FROM applicant_meta as aa GROUP BY meta_appl_id ) as bb; 

请根据需要添加其他可能的列。 我在这里显示了2列。