如何插入“concat”?在现有的mysql查询? [英] How do i insert a "concat" on existing mysql query?
问题描述
您好,
我有这个查询,我希望在()之间连接值。我该怎么办呢?
Sql查询:
Hello,
I have this query that i want to concat the values in between the "()". How can i do it correctly?
Sql query:
string SQL = "SELECT a.id_veiculo, a.id_empresa, a.nome_condutor, a.empresa_visitante, a.empresa_visitar, a.visitado, a.ncartao, (a.data + a.hora) as 'Entrada', a.obs,a.sector, (b.data + b.hora) as 'Saida' FROM entradas a LEFT OUTER JOIN saidas b ON a.data = b.data AND a.hora = b.hora and a.sector WHERE id_empresa = @tabempresa; ";
编辑:
string SQL = "SELECT a.id_veiculo, a.id_empresa, a.ncartao, a.nome_condutor, a.empresa_visitante, a.empresa_visitar, a.visitado, CONCAT(a.data,a.hora) as 'Entrada',a.sector,a.obs, CONCAT(b.data,b.hora) as 'Saida' FROM entradas a LEFT OUTER JOIN saidas b ON a.data = b.data AND a.hora = b.hora and a.sector WHERE id_empresa = @tabempresa; ";
此字符串工作正常,但我的值如2016-03-0109:58:00,我想要它如此2016-03-01 / 09:58:00
我的尝试:
尝试使用CONCAT复制此字符串,我想要组合数据,如下所示:
string SQL =SELECT a .id_veiculo,a.id_empresa,a.nome_condutor,a.empresa_visitante,a.empresa_visitar,a.visitado,a.ncartao,CONCAT(a.data,a.hora)as'Entrada',a.obs,a.sector, (b.data,b.hora)as'Seida'FROM entradas LEFT OUTER JOIN表示b on a.data = b.data AND a.hora = b.hora and a.sector WHERE id_empresa = @tabempresa;
This string works fine, but i have the value in it like "2016-03-0109:58:00" and i want it to be like so "2016-03-01 / 09:58:00"
What I have tried:
Tryied to replicate this string with the CONCAT where i wanted to combine data, like so:
string SQL = "SELECT a.id_veiculo, a.id_empresa, a.nome_condutor, a.empresa_visitante, a.empresa_visitar, a.visitado, a.ncartao, CONCAT(a.data, a.hora) as 'Entrada', a.obs,a.sector, (b.data, b.hora) as 'Saida' FROM entradas a LEFT OUTER JOIN saidas b ON a.data = b.data AND a.hora = b.hora and a.sector WHERE id_empresa = @tabempresa;
推荐答案
根据文档 [ ^ ],C. ONCAT
函数接受多个字符串参数。您只需要在字段之间传递分隔符:
According to the documentation[^], theCONCAT
function accepts multiple string arguments. You just need to pass the separator in between the fields:
CONCAT(a.data, ' / ', a.hora)
这篇关于如何插入“concat”?在现有的mysql查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!