I want to do something like below:
DELETE UserPredictions
GROUP BY UserId
HAVING COUNT(*) < 500
But I\'m getting a syntax error. Is
You can do so much with using row_number() OVER (partition by ) and CTE's, but only if your RDBMS supports it.
Example:
WITH CTE AS
(
SELECT UserId,
ROW_NUMBER() OVER (PARTITION BY UserId ORDER BY UserId) AS rowcount
FROM UserPredictions
)
DELETE FROM CTE
WHERE rowcount < 500
Additional info about the row count function:
https://docs.microsoft.com/en-us/sql/t-sql/functions/row-number-transact-sql?view=sql-server-2017