学无先后,达者为师

网站首页 编程语言 正文

SQL查询出的两列合并成一列显示

作者:多放香菜少加葱 更新时间: 2022-07-21 编程语言

一、Mysql

使用concat函数

## 可以拼接多个列
select concat(app_name,',',url) as str from apps
# 使用concat_ws函数
## CONCAT_WS(separator,str1,str2,...)
## separator,分隔符
## str1,str2为要拼接的字符
select CONCAT_WS(',',app_name,url) as str from apps

二、Oracle

-- 使用concat函数
---- 只能传两个参数,因此,如果需要拼接多个字符串,可是嵌套concat函数达到需求,不过不推荐
select concat(app_name,url) as str from apps
-- 使用 ||
---- 可以拼接多个字符
select app_name || ',' || url as str from apps

三、SQLServer

+号连接,列名用+连接查询                                             

四、UNION

select tp.combination_name as t 
from 
t_service_price as tp;
            UNION
 select tp.subheading as t 
 from 
 t_service_price as tp;

原文链接:https://blog.csdn.net/qq_41512902/article/details/125716136

栏目分类
最近更新