我是mysql的新手。我有代码,但它显示字节数组为什么? 抱歉我的英文:(
SELECT p.city_id,p.name city, CONCAT("[",
GROUP_CONCAT(CONCAT('{id:"', a.id, '", address:"', a.address, '"}')),
"]") As sahalar
FROM cities AS p LEFT JOIN carpet_fields As a ON(p.city_id = a.city_id)
GROUP BY p.city_id, p.name ORDER BY p.city_id
它必须显示json数据但是。结果是
错误的结果
city_id name sahalar
1 ADANA 0x5B7B69643A223236222C20616464726573733A2248757A75
正确的结果
city_id name sahalar
1 ADANA [{id:"1A", address:"Huzurevleri Mah.77232 Sk. ADANA / ÇUKUROVA"},{id:"1B", address:"KARSLILAR MAH. 82008. SOK. / MAHFESIGMAZ"}]
答案 0 :(得分:0)
我找到了解决方案
SET SESSION group_concat_max_len = 1000000;
SELECT p.city_id,p.name city,
CONCAT("[",
GROUP_CONCAT( CONCAT('{id:"', CAST(a.id as char(10)), '", address:"', a.address, '"}') ),
"]") As sahalar
FROM cities AS p
LEFT JOIN carpet_fields As a ON(p.city_id = a.city_id)
GROUP BY p.city_id, p.name ORDER BY p.city_id