Use a subquery to get the distinct values, then use ROW_NUMBER()
in the main query.
SELECT city, ROW_NUMBER() OVER ()
FROM (
SELECT DISTINCT city
FROM addresses
WHERE city IS NOT NULL AND city <> ''
) AS x
ORDER BY city
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…