MySQL-用逗号将两列合并为一

时间:2018-10-09 14:32:01

标签: mysql

我正在尝试将两列合并为一个逗号分隔的列。我确实尝试了concat函数,但没有成功。如何将它们合并为逗号?我真的需要用逗号将subcat_id移到cat_id。

cat_id  subcat_id
49,417  417
49,416  416
49      415
49      414

example

2 个答案:

答案 0 :(得分:0)

尝试CONCAT_WS(),如下所示:

def average_salary(data, lower_age, upper_age): 
    u = dict(sorted(data_cleaned.items()))
    count = 0  

    for i in u:
        age = u[i]['age']
        sal = u[i]['salary']
        tally = 0

        if age is not None and sal is not None and lower_age < float(age) < upper_age:
            tally += float(u[i]['salary'])
            print(u[i]['salary'])

答案 1 :(得分:0)

正确的答案很简单=;

更新表集字段CONCAT_WS(',',cat_id,sub_cat_id) 其中field = field