1

enter image description here

I would like to know how to display the data above into one row based on the field value i did a case select but it's coming up as the following image

(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,

enter image description here

1 Answer 1

2

You are trying to do it with conditional aggregation (meaning you are missing a group by clause an a max/min function) :

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
Sign up to request clarification or add additional context in comments.

4 Comments

Worth noting that this table layout goes against the grain entirely.
Thanks sagi this was very useful i knew i was missing something about the lead id.
BTW i did not create this database nor the table and you right Barry TheHatchet terrible disign.
No problem @MasterPage :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.