在许多列中拆分一列[Wordpress]

时间:2015-03-20 21:59:07

标签: mysql wordpress split multiple-columns

晚上好,

我想帮助我在许多列中拆分列,我尝试了很多案例但没有成功......

  

我有一个表格,其中的条目以列名称生成 - >   值:

photo image sample 1

  

我想要转换并从查询(选择)中获取:

photo image sample 2

如果有解决方案,我将不胜感激...... 谢谢!

1 个答案:

答案 0 :(得分:0)

尝试此查询。 (假设[test]作为你的表名)

SELECT
 t.lead_id
 , t.form_id
-- sub-query for Value1
, (SELECT VALUE FROM test as inner_t WHERE inner_t.lead_id = t.lead_id and inner_t.form_id = t.form_id 
                                       and inner_t.field_number = 1) as value1
-- sub-query for Value2
, (SELECT VALUE FROM test as inner_t WHERE inner_t.lead_id = t.lead_id and inner_t.form_id = t.form_id 
                                       and inner_t.field_number = 2) as value2
-- sub-query for Value3
, (SELECT VALUE FROM test as inner_t WHERE inner_t.lead_id = t.lead_id and inner_t.form_id = t.form_id 
                                       and inner_t.field_number = 3) as value3
-- sub-query for Value4
, (SELECT VALUE FROM test as inner_t WHERE inner_t.lead_id = t.lead_id and inner_t.form_id = t.form_id 
                                       and inner_t.field_number = 4) as value4
FROM test AS t
GROUP BY lead_id, form_id