[急!!!]求高手帮我写一个sql语句,在线等····(20)

  • 主题发起人 sunke520
  • 开始时间
S

sunke520

Unregistered / Unconfirmed
GUEST, unregistred user!
现在有个access表,表信息如下:站点 年 月 降水次数1 1990 1 21 1990 2 81 1990 3 7。 。 。 。。 。 。 。。 。 。 。1 1990 12 81 1991 1 31 1991 2 5。 。 。 。。 。 。 。 。 。 。 。现在我要查询1990年9月到1991年2月的降水次数在窗体上放了4个combobox,分别指的是起始年,起始月,终止年,终止月Startyear:=combobox1.text;endyear:=combobox2.text;startyue:=combobox3.text; //选9月endyue:=combobox4.text; //选2月我写的语句如下: select 站点,降水次数 from 表 where 年 between Startyear and endyear and 月 between startyue and endyue group by 站点,年,月 想问下这样选出来的月份是9月到2月的吗?如果不符合,该怎么写?请各位大虾帮忙啊。。。
 
你试一下不是知道了
 
给你一个表,你可以根据这个看看结果select '1' as 站点 ,1990 as 年, 1 as 月 ,'12' as 降水次数 into #表insert into #表 values ('1',1990,2,'6')insert into #表 values ('1',1990,3,'5')insert into #表 values ('1',1990,4,'4')insert into #表 values ('1',1990,5,'3')insert into #表 values ('1',1990,6,'2')insert into #表 values ('1',1990,7,'1')insert into #表 values ('1',1990,8,'1')insert into #表 values ('1',1990,9,'2')insert into #表 values ('1',1990,10,'13')insert into #表 values ('1',1990,11,'18')insert into #表 values ('1',1990,12,'28')insert into #表 values ('1',1991,1,'18')insert into #表 values ('1',1991,2,'38')insert into #表 values ('1',1991,3,'38')insert into #表 values ('1',1991,4,'23')insert into #表 values ('1',1991,5,'23')insert into #表 values ('1',1991,6,'24')insert into #表 values ('1',1991,7,'22')insert into #表 values ('1',1991,8,'23')insert into #表 values ('1',1991,9,'74')insert into #表 values ('1',1991,10,'73')insert into #表 values ('1',1991,11,'23')insert into #表 values ('1',1991,12,'74')insert into #表 values ('1',1992,1,'18')insert into #表 values ('1',1992,2,'38')insert into #表 values ('1',1992,3,'38')insert into #表 values ('1',1992,4,'23')insert into #表 values ('1',1992,5,'23')insert into #表 values ('1',1992,6,'24')insert into #表 values ('1',1992,7,'22')insert into #表 values ('1',1992,8,'23')insert into #表 values ('1',1992,9,'74')insert into #表 values ('1',1992,10,'73')insert into #表 values ('1',1992,11,'23')insert into #表 values ('1',1992,12,'74')--你自己的方法肯定不行啊select 站点,降水次数 from 表 where 年 between Startyear and endyear and 月 between startyue and endyue group by 站点,年,月 select * from #表 where 年 between 1990 and 1991 and 月 between 9 and 2--这种方法,先查询起始年份当年满足条件的数据,再查询结束年份当年满足条件的数据,最后查询中间年份所有月份的select 站点,降水次数 from 表 where (年 = Startyear and 月 > =startyue) or (年 = Endyear and 月<=endyue ) or (年 > Startyear and 年< Endyear )select * from #表 where (年 =1990 and 月>=9) or (年=1992 and 月<= 2) or ( 年>1990 and 年<1992) order by 年,月
 
select 站点,降水次数 from 表 where (年 = Startyear and 月 > =startyue) or (年 = Endyear and 月<=endyue ) or (年 > Startyear and 年< Endyear )这种方法如果统计的时间不跨年的话,就有问题,因为用的是 or我觉应该把年月结合成一个查询条件 ,SQL用得不多,所以不会写具体的语句
 
感谢楼上的帮忙,谢谢
 
顶部