Convert one row into multiple rows with fewer columns

后端 未结 3 1971
小鲜肉
小鲜肉 2020-12-12 04:44

I\'d like to convert single rows into multiple rows in PostgreSQL, where some of the columns are removed. Here\'s an example of the current output:

name | st         


        
3条回答
  •  猫巷女王i
    2020-12-12 05:34

    SELECT
      times.name, x.t, x.val
    FROM
      times cross join lateral (values('st',st),('ot',ot),('dt',dt)) as x(t,val)
    WHERE
      x.val <> 0;
    

提交回复
热议问题