0

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?

Tural Gurbanov
  • 742
  • 2
  • 7
  • 27

1 Answers1

0

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.

Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
  • First of all SphinxQL doesn't support several filtering conditions in HAVING statement. Second, SphinxQL doesn't support OR operator. – Tural Gurbanov Nov 23 '14 at 21:11