尚学堂给同学们带来全新的Java300集课程啦!java零基础小白自学Java必备优质教程_手把手图解学习Java,让学习成为一种享受_哔哩哔哩_bilibili
本章所用到案例数据来自于上一章节,如果有想使用该数据的读者可以查看上一章节。
这一章节我们想要了解的是PG聚合操作中使用到的filter子句,这个filter子句是ANSI SQL标准中的关键字,并不是PG的专用SQL关键字。如果我们想了解中国、美国、日本、法国、德国、加拿大从1960~2018年中每隔十年的GDP平均值情况,我们可能会写出着这样的SQL,
select country_name,sum(case when year>=1960 and year<1970 then gdp else null end) as "1960~1969", sum(case when year>=1970 and year<1980 then gdp else null end) as "1970~1979", sum(case when year>=1980 and year<1990 then gdp else null end) as "1980~1989", sum(case when year>=1990 and year<2000 then gdp else null end) as "1990~1999", sum(case when year>=2000 t