SQL Server 之间 [英] SQL Server BETWEEN

查看:22
本文介绍了SQL Server 之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含年、月和几个数字列的表格

I have a table which has Year, Month and few numeric columns

Year   Month  Total
2011     10    100
2011     11    150
2011     12    100  
2012     01    50
2012     02    200

现在,我想在 2011 年 11 月和 2012 年 2 月之间 SELECT 行.请注意,我希望查询使用范围.就像我在表中有一个日期列一样..

Now, I want to SELECT rows between 2011 Nov and 2012 FEB. Note that I want the to Query to use range. Just as if I had a date column in the table..

推荐答案

(Year > @FromYear OR Year = @FromYear AND Month >= @FromMonth)
AND (Year < @ToYear OR Year = @ToYear AND Month <= @ToMonth)

这篇关于SQL Server 之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆