我正在尝试将所有地址与状态连接起来,假设我的行具有相同的状态和不同的地址,所以我想运行将带来一些东西的查询
state | Address
Maharastra ABC,DEF,XYZ
DELHI | WRU
目前我的 table 是
username | state | Address
abc Maharastra ABC
abc Maharastra DEF
abc Maharastra XYZ
abc DELHI WRU
def Maharastra ABC
def Maharastra OVU
def GOA IKL
def DELHI WRU
我尝试了什么
SELECT address,state from location where username='abc' GROUP BY state
我的输出是
address state
ABC Maharastra
WRU DELHI
最佳答案
GROUP_CONCAT()
是你要找的
SELECT STATE, GROUP_CONCAT(Address ORDER BY Address SEPARATOR ',')
FROM location where username='abc'
GROUP BY STATE
关于mysql - 如何在mysql中将地址与状态连接起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30223177/