Return column name and distinct values

前端 未结 3 2043
生来不讨喜
生来不讨喜 2021-01-22 02:09

Say I have a simple table in postgres as the following:

+--------+--------+----------+
|  Car   |  Pet   |   Name   |
+--------+--------+----------+
| BMW    |           


        
3条回答
  •  粉色の甜心
    2021-01-22 02:47

    SQL Fiddle

    SELECT distinct
           unnest(array['car', 'pet', 'name']) AS col,
           unnest(array[car, pet, name]) AS vals
    FROM t
    order by col
    

提交回复
热议问题