How many edits until Copy Editor (proper)?

Shows a user's total edits so far, how many edits until the "Strunk and White" (now 80 at SO)
badge, and how many edits until the "Copy Editor" badge (now 500 at SO).

Q&A for programmers

-- How many edits until Copy Editor (proper)?
-- Shows a user's total edits so far, how many edits until the "Strunk and White" (now 80 at SO)
-- badge, and how many edits until the "Copy Editor" badge (now 500 at SO).
-- 2011-12-18 Fix: multiple edits on the same post count once only.
-- only edits to title and body count, editing tags alone does not.
-- Source of info:
-- http://meta.stackoverflow.com/questions/67397/list-of-all-badges-with-full-descriptions
DECLARE @USER int = ##UserId##;
SELECT COUNT(DISTINCT ph.PostId) AS 'Number of Edits', -- every post counts once only
80 - COUNT(DISTINCT ph.PostId) AS 'Edits until "Strunk and White"',
500 - COUNT(DISTINCT ph.PostId) AS 'Edits until "Copy Editor"'
FROM PostHistory ph
JOIN Posts p ON p.Id = ph.PostId AND p.OwnerUserId <> @User
WHERE ph.UserId = @User
AND ph.PostHistoryTypeId BETWEEN 4 AND 5 -- only edits to title & body count