我有一个包含以下字段名称、地址、城市、邮编等的表格。
如何选择具有相同值的城市列?
如果您正在寻找纽约的所有条目,假设您的表名称为位置
SELECT name, address, zip, city FROM locations WHERE city LIKE "New York"
如果您希望所有条目按城市排序,以便它们聚集在一起:
SELECT name, address, zip, city FROM locations ORDER BY city DESC
如果要收集每个城市的名称列表:
SELECT GROUP_CONCAT(name) FROM locations GROUP BY city;
目前还不清楚你想要什么。
如果您想要一个多次出现的城市列表,您可以使用:
select city, count(city) Total
from yourtable
group by city
having count(city) > 1
如果要根据城市名称返回数据,您将使用:
select *
from yourtable
where city = 'yourCity'
select city from table_name group by city having count(city) > 1;