我想知道如何根据字段值将上面的数据显示为一行我做了一个案例选择,但它会出现如下图所示
(SELECT lead_id,
case lead_id
case field_number when 1 then value end as firstname
case field_number when 1 then value end as firstname,
case field_number when 2 then value end as lastname,
case field_number when 10 then value end as email,
答案 0 :(得分:2)
您正尝试使用条件聚合(意味着您缺少group by子句和max / min函数):
SELECT lead_id,
MAX(CASE WHEN field_number = 1 then value end) as firstname,
MAX(CASE WHEN field_number = 2 then value end) as lastname,
MAX(CASE WHEN field_number = 10 then value end) as email
FROM YourTable
GROUP BY lead_id