-2

I have the following query

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

This query returns 100 as result, i need to know how to add another condition in where clause using LIKE and getting the same result (100)

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

The name column event if it's added it should have no effect on the final result

drex drex
  • 205
  • 1
  • 8

3 Answers3

1

Here is two way of doing this, but what is the meaning of this?

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

Or:

select count(person),  from [table]
where (date > '2015-01-01' and (name LIKE '%sometext%' or 1 = 1))
group by person
Giorgi Nakeuri
  • 34,370
  • 8
  • 37
  • 69
0

Are you aware of the TOP clause?

select TOP 100 count(person) As PersonCount, Person
from [table]
where (date > '2015-01-01' and name LIKE '%?%')
group by person
Tim Schmelter
  • 429,027
  • 67
  • 649
  • 891
0

Try this:

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

Assuming that there are more than 100 results for which name is containing ? else the result will differ.

Rahul Tripathi
  • 161,154
  • 30
  • 262
  • 319