问一个关于数据库查询的为题!怎么获得小于当前年份固定月份的数据?

来源:百度知道 编辑:UC知道 时间:2024/06/25 20:45:34
就是说,比如我输入10 就获得2009年10月份 以前每年10月份的数据?
如 2008/10、2007/10、2006/10、2005/10、2004/10 …… 2000/10
的数据?
假设有这样的表
数据如下;
userid sell time
1 1200.10 2000/1
2 1200.10 2000/2
1 1100.10 2000/2
1 1200.00 2000/1
1 1200.10 2000/1
1 1200.10 2000/3
1 1200.10 2000/4
1 1200.10 2000/10
1 1200.10 2000/11
1 1200.10 2000/12
1 1200.10 2001/1
……
1 1200.10 2001/10
1 1200.10 2002/11
……
1 1200.10 2009/12
这样怎么获得 从2000年 到2009年 每年10月份的数据?
嗯,谢谢哈。。。知道了!
还有个问题就是。。。那怎么统计每年的数据 ? 就是上面说的 2000年 到 2009年 所有的数据? 分组统计出来
谢谢啊

select * from table where time like '%10'

就可以获得TIME中以10结尾的数据,即每年10月的数据.

要每年的话:(ORACLE)
select substr(time,1,4),sum(sell) from TABLE group by substr(time,1,4)

(SQL):select substring(time,1,4),sum(sell) from TABLE group by substr(time,1,4)
就可以了.

建立存储过程
CREATE PROC SP_query
@month char(2)
as
begin
exec(‘select * FROM TABLE where time like’+ '''%/'+ @month + '''')
end

执行

exec SP_qyery 10

就得到你要的数据了

delclare @m char(2)
set @m='10'
select * from table where month(time)=@m

select * from 表 where to_char(time ,'mm')='10'