赞
踩
①CONCAT() 拼接字符串基本型:SELECT CONCAT ( lastname , firstname) AS student_name FROM kalacloud_student;
②使用空格拼接字符串:仍然使用 SELECT CONCAT() 命令,空格需要使用' ' 两个单引号引起来。SELECT CONCAT(firstname, ' ', subject) AS studentDetail FROM kalacloud_student;
③使用特殊符号拼接字符串:SELECT CONCAT(firstname, '-', subject, '-', qualification) AS detail FROM kalacloud_student;
④在筛选查询中进行字符串拼接并显示在表格里:SELECT CONCAT(qualification, ' ', firstname, ' - ', subject) AS 候选人资料, wechat_id, phone FROM kalacloud_student WHERE qualification = 'MPhil';
⑤字符串与中文文本的拼接:SELECT CONCAT('候选人:', lastname,firstname, ' 学科:',subject,' 学历:', qualification) AS 简历 FROM kalacloud_student ORDER BY qualification DESC;
⑥CONCAT_WS() 仅需写一次分隔符即可拼接所有字符串:SELECT CONCAT_WS(' / ', firstname, phone, subject, qualification) AS Detail FROM kalacloud_student;
总结:CONCAT() 字符串拼接功能在日常工作场景中使用非常频繁,但它的原理很好理解。任何非数据库中的字符串都加上' 单引号引起来即可。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。