我需要在PostgreSQL中将行转换为列。如果有人能在这上面放一些棚就太好了。我试着用交叉表解决这个问题,但没有运气。
select *
from crosstab(
'select
count(distinct no_of_cars) as no_of_cars,
car_type,
month
from abc
group by 2, 3
order by 3',
'select distinct month from abc order by month'
) as ct(
no_of_cars text,
car_type text,
month text
)
随附数据截图。
1条答案
按热度按时间mf98qq941#
我更喜欢筛选聚合,因为我发现它更容易维护和理解: