SQL server添加where子句不会影响结果

时间:2015-04-21 12:32:31

标签: sql sql-server

我有以下查询

  select count(person),  from [table]
  where (date > '2015-01-01')
  group by person

此查询返回100作为结果,我需要知道如何使用LIKE在where子句中添加另一个条件并获得相同的结果(100)

  select count(person),  from [table]
  where (date > '2015-01-01' and name LIKE '%?%')
  group by person

如果添加了名称列事件,它应该对最终结果

没有影响

3 个答案:

答案 0 :(得分:1)

这是两种方法,但这是什么意思?

select count(person),  from [table]
where (date > '2015-01-01' and (name LIKE '%' or name is null))
group by person

或者:

select count(person),  from [table]
where (date > '2015-01-01' and (name LIKE '%sometext%' or 1 = 1))
group by person

答案 1 :(得分:0)

您是否了解TOP clause

select TOP 100 count(person) As PersonCount, Person
from [table]
where (date > '2015-01-01' and name LIKE '%?%')
group by person

答案 2 :(得分:0)

试试这个:

select top 100 count(person),  from [table]
where (date > '2015-01-01' and name LIKE '%?%')
group by person

假设name包含?的结果超过100个,则结果会有所不同。