How to select Column value as Column name with conditions in SQL table

后端 未结 3 1022
小鲜肉
小鲜肉 2020-12-20 01:21

I\'m new to SQL. I have a table \'Customers\' and it looks like this.

\"enter

3条回答
  •  猫巷女王i
    2020-12-20 01:35

    I have not tested this, but give something like this a try:

    Select c.Name,
        (Select c2.Value from customers c2 Where c2.Name = c.Name And c2.Field = 'Gender') as Gender,
        (Select c2.Value from customers c2 Where c2.Name = c.Name And c2.Field = 'Age') as Age
    From Customers c
    Group By c.Name
    

    PS I apologize for the awful formatting...had to type this from my phone.

提交回复
热议问题