假设我有一个名为和cities
字段的表。数据如下所示:state
city
State City
Ohio Eaton
Ohio Columbus
Ohio Dayton
Ohio Greenville
New York New York
New York Albany
New York Syracuse
我希望能够做到这一点:
select state, join(city,',') from cities
group by state
...返回这个:
State City
Ohio Eaton,Columbus,Dayton,Greenville
New York New York,Albany,Syracuse
我需要为此创建一些疯狂的 UDF 吗?如果没有函数,有没有办法应用一些 SQL 魔法来实现这一点?