我正在查找如何筛选查询的数据结果,如果某个位置使用特殊的where子句。很难解释我在寻找的话做,但这里是我的例子:Where子句筛选某些选定数据的结果
我有一个从一系列的位置拉结果的查询:
Select a.Location, a.Invoice_date, a.service, a.QTY, b.user
From Invoice_detail as a inner join Invoice_tb as b on
a.invoice_number = b.invoice_number and a.location = b.location
where invoice_date between @startdate and @enddate and Not (a.location = 1 and a.service = 1)
order by a.location
这给了我下面的输出:
Location Invoice Date Service QTY User
1 1/2/16 1 1 Tim
1 1/2/16 1 1 Bob
1 1/2/16 1 1 Tim
1 1/2/16 2 1 Bob
1 1/2/16 3 1 Bob
2 1/2/16 1 1 Tim
2 1/2/16 2 1 Bob
2 1/2/16 4 1 Tim
3 1/2/16 1 1 Bob
3 1/2/16 6 1 Tim
3 1/2/16 1 1 Bob
如果位置为'1',我想不返回服务'1'。但我确实想将服务1退回到其他任何位置。所以,我想我的输出看起来像这样:
Location Invoice Date Service QTY User
1 1/2/16 2 1 Bob
1 1/2/16 3 1 Bob
2 1/2/16 1 1 Tim
2 1/2/16 2 1 Bob
2 1/2/16 4 1 Tim
3 1/2/16 1 1 Bob
3 1/2/16 6 1 Tim
3 1/2/16 1 1 Bob
你就不能添加条件'AND NOT(服务= 1和位置= 1)'? –