sql - Merge data from different rows to different columns -


this question has answer here:

i have table (t)

user | language | value ----------------------- 1    |1         | string 1    |2         | otherstring 

and want merge/join them this

user | language_1 | language_2 -------------------------------- 1    |string      | otherstring 

i tried this

select       user,              (case when language = 1 value end) language_1,              (case when language = 2 value end) language_2         t 

but result (i should have expected this)

user | language_1 | language_2 -------------------------------- 1    |string      | null 1    |null        | otherstring 

whats right way it?

you need aggregation

select user,          max(case when language = 1 value end) language_1,          max(case when language = 2 value end) language_2  t group user 

Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -