SQL 查询将 ID 排序为 ASC 和 Zip 不得重复
SQL query to sort the ID as ASC and Zip must not dup
我有一个这样的 SQL 语句:
SELECT TOP 100 id,
lastname,
firstname,
address1,
city,
state,
zip
FROM leads
WHERE id > 100
ORDER BY id ASC
现在我希望 100 个结果的 ZIP 与 1 个类似的查询语句不同(不是重复)。
SELECT TOP 100 l.id,
l.lastname,
l.firstname,
l.address1,
l.city,
l.state,
l.zip
FROM leads l
WHERE l.id = (select MIN (id) FROM leads l2 where l2.zip=l.zip)
ORDER BY l.id ASC
我有一个这样的 SQL 语句:
SELECT TOP 100 id,
lastname,
firstname,
address1,
city,
state,
zip
FROM leads
WHERE id > 100
ORDER BY id ASC
现在我希望 100 个结果的 ZIP 与 1 个类似的查询语句不同(不是重复)。
SELECT TOP 100 l.id,
l.lastname,
l.firstname,
l.address1,
l.city,
l.state,
l.zip
FROM leads l
WHERE l.id = (select MIN (id) FROM leads l2 where l2.zip=l.zip)
ORDER BY l.id ASC