I have a query of the form
SELECT a, b, c from Tbl where [conditions] IN
(SELECT a from Tbl where [conditions]
GROUP BY a HAVING COUNT(*) > N)
ORDER BY a DESC, b LIMIT 100
[conditions]
is basically a series of AND
statements and a
is a column with possible duplicates. Column a
+ b
is a unique combination. Currently I am using the GROUP BY
clause simply to get the COUNT(*) > N
to work. I want to return rows for column entries that satisfy the [conditions]
and have at least N
rows. As you can see the query is basically the same as the conditions are repeated. What is a better way to achieve the above?
Thanks.
Aucun commentaire:
Enregistrer un commentaire