[英]SQL: find distinct values for only few columns
我有一張如下所示的表格:
ID Address1 City State Zip YearBuilt
1 704 Grant Ave X Y 11111 2000
2 704 Grant Ave X Y 11111 2000
3 704 Grant Ave X Y 11111 2000
4 303 2nd St A B 22222 1900
5 303 2nd St A B 22222 1900
6 44 North ST C D 33333 1950
現在我只想擁有那些具有不同Address1、City、State 和 Zip的行。 ID 不能用作標識符,因為對於相同的地址,它具有不同的 ID。 我可以保留最高 ID。
SELECT MIN(ID), Address1, City, State, Zip FROM ... GROUP BY Address1, City, State, Zip
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.