晚上好,
我想帮助我在许多列中拆分列,我尝试了很多案例但没有成功......
我有一个表格,其中的条目以列名称生成 - > 值:
我想要转换并从查询(选择)中获取:
如果有解决方案,我将不胜感激...... 谢谢!
答案 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