如果值为true,则获取列名称

时间:2018-09-28 13:49:23

标签: sql postgresql

说我有桌子:

table_name: animal
column_names:
"dog": 'f',
"cat": 'f',
"cow": 't'
.
.
.

如何显示列名“ cow”?

谢谢!

1 个答案:

答案 0 :(得分:0)

唯一简单的方法-直接检查每一列:

select 
  case 
    when dog=true then 'dog'
    when cat=true then 'cat'
    when cow=true then 'cow'
  end as col
from animal
相关问题