Skip to content

Instantly share code, notes, and snippets.

@Hirurg103
Last active July 17, 2018 16:19
Show Gist options
  • Save Hirurg103/d1a9f1b22ca6cb7b786ae769b38a7c4a to your computer and use it in GitHub Desktop.
Save Hirurg103/d1a9f1b22ca6cb7b786ae769b38a7c4a to your computer and use it in GitHub Desktop.
# For mysql
SET @id:=1
SELECT id, @num:=@num + 1 AS num
FROM (
SELECT id FROM email_notifications ORDER BY created_at ASC
) AS t
HAVING MOD(num, 101) = 0;
# For postgresql
SELECT id FROM (
SELECT id, (ROW_NUMBER() OVER(ORDER BY id DESC)) AS num FROM locations
) AS tn
WHERE num % 101 = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment