SphinxSearch: complex having statement

91 views Asked by At

I have table person_content with next columns:

  • person_id INT
  • content_id INT
  • is_star BOOL

I need to select all persons, who are related to more than N content_ids or has is_star flag, using SphinxQL.

The first part of my problem can be solved using COUNT, GROUP BY and HAVING:

SELECT person_id, COUNT(DISTINCT content_id) as t
FROM person_content
GROUP BY person_id HAVING t > N;

Is it possible to add is_star condition to the request? Or, for example, somehow add is_star * N to t?

1

There are 1 answers

1
Get Off My Lawn On

If I understand correctly, you want those where t > N OR is_star is true. If so, I think that this should work for you:

SELECT person_id, COUNT(DISTINCT content_id) as t, is_star
FROM person_content
GROUP BY person_id HAVING t > N or is_star;

Anything in the having clause MUST be a selected column in your select statement.