所以这是我现在的问题:
SELECT *,
JOIN users u
JOIN user_addresses ua ON u.id = ua.userId_fk
JOIN timeSlots ts ON u.id = ts.userId_fk
我在solr中使用这个来索引用户。时间段如下:
ID | userId_fk | dayOfWeek | startTime | endTime
1 100 MONDAY 10:00 12:00
如何将这个时隙数据作为逗号分隔的列表或类似的列表进行连接,以便将其解析为javascript对象?
所需输出示例:
id | address | userName | timeslots
1 123 ave someName MONDAY,10:00,12:00 TUESDAY,12:00,18:00
最佳答案
希望这会有帮助
SELECT u.id , ua.address , userName , timeslots, concat(dayOfWeek, ',' ,startTime, ',' ,endTime ) timeslots
JOIN users u
JOIN user_addresses ua ON u.id = ua.userId_fk
JOIN timeSlots ts ON u.id = ts.userId_fk
你也可以将它分组。如果要将多个时隙与分隔的空间组合在一起
SELECT u.id , ua.address , userName , timeslots, group_concat(concat(dayOfWeek, ',' ,startTime, ',' ,endTime ) separator ' ') as timeslots
JOIN users u
JOIN user_addresses ua ON u.id = ua.userId_fk
JOIN timeSlots ts ON u.id = ts.userId_fk
group by userName
关于mysql - 如何以逗号分隔的字符串形式连接表?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38308762/