用于筛选配置日期列表的TSQL查询

用于筛选配置日期列表的TSQL查询,sql,sql-server,date,logic,Sql,Sql Server,Date,Logic,如果我想要下表中的日期/记录,比如年份大于或等于2012,月份大于9月,我应该如何形成查询 这个查询不起作用,它带来了2012年(7,8,9,10,11,12)和2013年(1到12)几个月,这是不正确的,因为我想看到2012年(9,10,11,12)和2013年(1到12)。包括2012年第7个月和第8个月 select * from ConfigurationDate where Year >= 2012 OR ( Year = 2012 AND Month >= 9 ) Ord

如果我想要下表中的日期/记录,比如年份大于或等于2012,月份大于9月,我应该如何形成查询

这个查询不起作用,它带来了2012年(7,8,9,10,11,12)和2013年(1到12)几个月,这是不正确的,因为我想看到2012年(9,10,11,12)和2013年(1到12)。包括2012年第7个月和第8个月

select * from ConfigurationDate
where Year >= 2012 OR ( Year = 2012 AND Month >= 9 )
Order By Year,Month ASC
表架构

DateId INT Auto Inc

Year INT

Month INT
DateId           Year        Month
1                2012          7

2                2012          8

3                2012          9

4                2012          10

5                2012          11

6                2012          12

7                2013          1

8                2013          2

9                2013          3

10               2013          4

11               2013          5

12               2013          6

13               2013          7

14               2013          8

15               2013          9

16               2013          10
虚拟数据

DateId INT Auto Inc

Year INT

Month INT
DateId           Year        Month
1                2012          7

2                2012          8

3                2012          9

4                2012          10

5                2012          11

6                2012          12

7                2013          1

8                2013          2

9                2013          3

10               2013          4

11               2013          5

12               2013          6

13               2013          7

14               2013          8

15               2013          9

16               2013          10

实际上,考虑到这一点,我不需要在第一个条件中再次包含2012年的日期,因为它包含在第二个条件中。答案如下

select * from ConfigurationDate
where Year > 2012 OR ( Year = 2012 AND Month >= 9 )
Order By Year,Month ASC

好吧,我好像已经弄明白了。我会在几秒钟内给出答案