如何将SQL查询出的两列合并成一列显示,并用逗号隔开
DROP TABLE IF EXISTS `apps`;
CREATE TABLE `apps` (
`id` int NOT NULL AUTO_INCREMENT,
`app_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '站点名称',
`url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',
`country` char(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '国家',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
INSERT INTO `apps` VALUES (1, 'QQ', 'http://im.qq.com/', 'CN');
INSERT INTO `apps` VALUES (2, '微博 APP', 'http://weibo.com/', 'CN');
INSERT INTO `apps` VALUES (3, '淘宝 APP', 'https://www.taobao.com/', 'CN');
SET FOREIGN_KEY_CHECKS = 1;
1 mysql
select concat(app_name,',',url) as str from apps
select CONCAT_WS(',',app_name,url) as str from apps
2 orcal
select concat(app_name,url) as str from apps
select app_name || ',' || url as str from apps