大家好,又见面了,我是你们的朋友全栈君。
涉及方法:concat, concat_ws, group_concat
数据准备:
CREATE TABLE `app` (
`app_id` int DEFAULT '0',
`version_code` int DEFAULT '0',
`download_count` int DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `app`(`app_id`, `version_code`, `download_count`) VALUES (1, 10, 90);
INSERT INTO `app`(`app_id`, `version_code`, `download_count`) VALUES (1, 11, 100);
INSERT INTO `app`(`app_id`, `version_code`, `download_count`) VALUES (1, 10, 20);
INSERT INTO `app`(`app_id`, `version_code`, `download_count`) VALUES (2, 15, 10);
INSERT INTO `app`(`app_id`, `version_code`, `download_count`) VALUES (2, 16, 15);
INSERT INTO `app`(`app_id`, `version_code`, `download_count`) VALUES (2, 17, 30);
INSERT INTO `app`(`app_id`, `version_code`, `download_count`) VALUES (2, 16, 5);
INSERT INTO `app`(`app_id`, `version_code`, `download_count`) VALUES (3, 2, 50);
INSERT INTO `app`(`app_id`, `version_code`, `download_count`) VALUES (4, 9, NULL);
select concat (app_id, ',', version_code, ',', download_count) as info from app;
select concat_ws (',', app_id, version_code, download_count) as info from app;
select app_id,
group_concat(distinct version_code ORDER BY version_code separator '-') as res1,
group_concat(concat_ws('-', version_code, download_count)) as res2
from app group by app_id;
注意点:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/187531.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有