有时需要将查询到的2类数据合并到一列显示,遇到这样情况很容易实现。
使用Concat( ) 函数即可。
例如:
需要将TestPointDataID和TestPointName显示在同一列
select * from TestPointList where TestTypeID=100587
使用Concat( )函数查询实现合并到一列中:
select concat( TestPointName , TestPointDataID) as Tp from TestPointList where TestTypeID=100587
名称和ID之间没有空格,不方便观察和使用。添加空格。
select CONCAT( concat( TestPointName,’ ’ ), TestPointDataID) as Tp from TestPointList where TestTypeID=100587
使用2次concat() 函数,将空格连接进去。
也可以使用其它符号分隔,如使用加号 “+”
select CONCAT( concat( TestPointName,’+’ ), TestPointDataID) as Tp from TestPointList where TestTypeID=100587