全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3210 14
2017-04-24
请问大家,如何采用sql语句,求出每年6、7、8三个月份的平均气温?

原始数据
temperature.zip
大小:(26.7 KB)

 马上下载

本附件包括:

  • temperature.csv

如下:
provinceyearmonthtemperature
安徽

1996

1

3

安徽

1996

2

3.8

安徽

1996

3

8.1

安徽

1996

4

15.2

安徽

1996

5

21.3

安徽

1996

6

24.9

安徽

1996

7

27.3

安徽

1996

8

27.9

安徽

1996

9

23.9

安徽

1996

10

17.7

安徽

1996

11

9.9

安徽

1996

12

6.4

安徽

1997

1

2.8

安徽

1997

2

5.4

安徽

1997

3

11.2

安徽

1997

4

16.4

安徽

1997

5

24

安徽

1997

6

26.5

安徽

1997

7

28

安徽

1997

8

28.5

安徽

1997

9

22.5

安徽

1997

10

19

安徽

1997

11

10.6

安徽

1997

12

5.9



我是这么写的,但是不行

proc sql;create table tmp1 as select distinct
province,year,
mean(temperature) as temperature_avgyear,
case when year in (6,7,8) then mean(temperature) else . end as temperature_avgwinter

from
temperature
group by province,year;
quit;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2017-4-24 15:51:32
我不会,但是帮你顶一下
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2017-4-24 15:57:11
z8938560 发表于 2017-4-24 15:51
我不会,但是帮你顶一下
非常感谢您!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2017-4-24 15:59:43
你试一下 select province,year, avg(temperature) from 表名
where month in (6,7,8)
group by province, year
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2017-4-24 16:04:48
baoluanlu 发表于 2017-4-24 15:59
你试一下 select province,year, avg(temperature) from 表名
where month in (6,7,8)
group by province ...
非常感谢!其实,我除了需要计算6、7、8三个月以外,还要计算全年的平均气温。如果采用了where month in (6,7,8),那么这个程序中就没法计算全年平均气温了啊
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2017-4-24 16:34:45
lizhewenbei 发表于 2017-4-24 16:04
非常感谢!其实,我除了需要计算6、7、8三个月以外,还要计算全年的平均气温。如果采用了where month in  ...
需要全年的话,直接把month那一段删了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群