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?
If I understand correctly, you want those where
t > NORis_staris true. If so, I think that this should work for you:Anything in the
havingclause MUST be a selected column in your select statement.