mysql 如何把兩個字段拼接起來

2021-08-04 17:26:31 字數 442 閱讀 7003

在mysql中有個關鍵字

concat_ws

關鍵字解釋:

根據特定的字元將不同的字段拼接在一起

例如:表  student

id  age  name

1    2     xiaohong

2    4     xiaoming

拼接:concat_ws("|","xiaoming","xiaohong") as  total

拼接結果:

total

xiaoming | xiaohong

concat_ws("xml","","",""...)

xml可以用其他的 替代     例如:   |    ,: ,  +,-,  t   ,\    ,等 只要便於區分便可

當然   一般跟 group by 關鍵字一起搭配使用

具體實現是根據業務來操作

mysql 兩個字段拼接 mysql 多個字段拼接

mysql的查詢結果行欄位拼接,能夠用以下兩個函式實現 1.concat函式 mysql select concat 1 2 3 from test concat 1 2 3 123 假設連線串中存在null,則返回結果為null mysql select concat 1 2 null,3 fro...

Mysql如何根據兩個字段排序?

假如我要對以下sql查詢語句的查詢結果進行排序 兩個欄位a,b select a,b,c,d,e from table name 1.先按照a公升序,再按照b降序 select a,b,c,d,e from table name order by a,b desc 也可以寫為 因為預設公升序,可以不...

GROUP BY 兩個字段

create table test a varchar 10 b varchar 10 c int insert into test values a 甲 1 insert into test values a 甲 1 insert into test values a 甲 1 insert int...