Sql server 2008 SQL 2008:如果一行中的两列具有这些值,则排除行
例如,早安目的:使用我查询中的这些给定数据Sql server 2008 SQL 2008:如果一行中的两列具有这些值,则排除行,sql-server-2008,Sql Server 2008,例如,早安目的:使用我查询中的这些给定数据 T0.Date T0.customer T0.total T1.Date, T1.Total 2.1.2017 BLABLA 2,400.00 3.8.2017 2,400.00 1.2.2017 BLOBLO 5,000.00 3.1.2017 5,000.00 1.1.2017 BLEBLE 3,000.00 2.5.2017 3,000.00 12.5.201
T0.Date T0.customer T0.total T1.Date, T1.Total
2.1.2017 BLABLA 2,400.00 3.8.2017 2,400.00
1.2.2017 BLOBLO 5,000.00 3.1.2017 5,000.00
1.1.2017 BLEBLE 3,000.00 2.5.2017 3,000.00
12.5.2016 BLABLA 1,000.00 1.25.2017 1,000.00
我怎样才能在查询中删除T0.Date=一月(1)和T1.Date=三月(3)所在行的行呢。我想在where子句中使用case,但我不知道如何开始条件。但是,如果T1.日期=2月(2日),那么T0.日期=1或最后一年的月份(2016年1月12日)无关紧要
更新:
预期产出:
T0.Date T0.customer T0.total T1.Date, T1.Total
2.1.2017 BLABLA 2,400.00 3.8.2017 2,400.00
1.1.2017 BLEBLE 3,000.00 2.5.2017 3,000.00
12.5.2016 BLABLA 1,000.00 1.25.2017 1,000.00
这是你想要的吗
where T0.Date <> '2017-01-01' or T1.Date <> '2017-03-03'
其中T0.日期“2017-01-01”或T1.日期“2017-03-03”
或者,如果您只是在寻找整个月:
其中不包括((t0.date>='2017-01-01'和t0.date<'2017-02-01'),以及
(t1.date>='2017-03-01'和t1.date<'2017-04-01')
)
这应该可以
where month(dateadd(month,1,T0_date))=month(T1_date) and year(dateadd(month,1,T0_date))=year(T1_date)
问题不清楚。你能用预期的输出清楚地解释一下吗?比如说,如果T1.日期是3月,那么T0.日期就不允许是1月。但是如果T1.Date是2月,那么可以将T0.Date与1月日期和以下日期(2016年)一起使用。好的,我考虑只使用月份,因为没有特定的日期。因为这些数据是通过日期范围创建的,所以会有很多日期。所以我的想法是使用MONTH()
where month(dateadd(month,1,T0_date))=month(T1_date) and year(dateadd(month,1,T0_date))=year(T1_date)