倾世奇缘安卓版:帮忙以下,?如何写这个sql语句

来源:百度文库 编辑:中科新闻网 时间:2024/04/30 08:04:23
有个表a,有字段编码,数据时间,数据值,
现在有一记录b,字段有编码,最大值,本月最大值,最大值和本月最大值都是数据值max(),只不过取值时间不同,
最大值的取值条件为数据时间>=2006-1-1 00:00:00 and 数据时间<=2006-12-31 00:00:00,
本月最大值取值条件为数据时间>=2006-1-1 00:00:00 and 数据时间<=2006-1-31 00:00:00
用一条sql语句写出,
谢谢各位!

insert into b (编码,最大值,本月最大值) values(编码,
(select max(data) from a where time>=2006-1-1 and time <=2006-12-31 ) , (select max(data) from a where time>=2006-1-1 and time <=2006-1-31 ) )

insert into b (编码,最大值,本月最大值)
select 编码,(select max(data) from a where time>=2006-1-1 and time <=2006-12-31 ),(select max(data) from a where time>=2006-1-1 and time <=2006-1-31 )
group by 编码