transpose column headers to rows in postgresql

前端 未结 5 1509
悲哀的现实
悲哀的现实 2020-12-06 00:59

I have a view which looks like this

          value1count     value2count value3count
          ----------------------------------------
             25             


        
5条回答
  •  情话喂你
    2020-12-06 01:19

    I could be not understanding...but the way I did this was to also select DISTINCT then select the average columns values I needed. Like this:

    SELECT DISTINCT contributing_factor_vehicle_1, AVG(number_of_cyclist_injured) FROM "table1".motor_vehicle_collisions_crashes 
    GROUP BY contributing_factor_vehicle_1
    ORDER BY avg(number_of_cyclist_injured) desc
    

    That's what created something like so:

    This was NYC motor vehicle crash data btw.

提交回复
热议问题