我有以下查询
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
如果添加了名称列事件,它应该对最终结果
没有影响答案 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个,则结果会有所不同。