我在Postgres的工作用表这样的划分:如何行之间在一个表中的Postgres
mon yyyy weather
Apr 2014 78.45
Apr 2015 77.32
May 2014 79.56
May 2015 78.43
我希望能够查询了一些成果,通过“星期一”命令,其中weather
列值按月份按年份划分。
换句话说,我要查询天气,其中四月2015年由四月分2014年
不过,我想编写查询中,使得我没有指定一个月或一年的方式,和查询自动根据2015年4月/ 2014年4月,然后2014年5月/ 2014年5月将值分为weather
,而无需每月和每年都输入,这很费力。
我有下面的代码,但这种扩展的列这不是我想要的:
select (select "Weather" from yoy
where mon = 'Apr' and yyyy = '2015'
)/(select "American" from yoy
where mon = 'Apr' and yyyy = '2014'
) as "weather_apr",
(select "Weather" from yoy
where mon = 'May' and yyyy = '2015'
)/(select "Weather" from yoy
where mon = 'May' and yyyy = '2014'
) as "weather_may",
from yoy;