-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
  • 35,155
  • 8
  • 47
  • 75
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
  • 450,073
  • 74
  • 686
  • 939
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
  • 168,305
  • 31
  • 280
  • 331