当前位置:网站首页>Oracle database merge row records, wmsys WM_ Use of the concat function and group in MySQL_ Use and comparison of concat (ID).

Oracle database merge row records, wmsys WM_ Use of the concat function and group in MySQL_ Use and comparison of concat (ID).

2022-06-11 16:42:00 Peach

Oracle: wmsys.wm_concat()

Put result set in one column , By comma ‘,’ separate

Columns such as :

oracle10g The above version provides the function of combining row to column into a string wmsys.wm_concat

   For example, there is a users The table is as follows :

  id yhm xm

  1 001 Xiaotang

  2 002 petty thief

  3 003 Xiao Zhang

  selectwmsys.wm_concat(yhm) user name , wmsys.wm_concat(xm) full name from users

   The execution result is :

   user name full name

  001,002,003 Xiaotang , petty thief , Xiao Zhang

 

wmsys.wm_concat() The parameters in can also make multiple , Use ”||” Splicing , The following example :

select deptno,wmsys.wm_concat(ename || '-' || job) name from emp group by deptno;

The results are shown in the following table :

deptno

ename

10

CLARK-MANAGER,MILLER-CLERK,KING-PRESIDENT

 

20

SMITH-CLERK,FORD-ANALYST,ADAMS-CLERK,SCOTT-ANALYST,JONES-MANAGER

30

ALLEN-SALESMAN,JAMES-CLERK,TURNER-SALESMAN,BLAKE-MANAGER,MARTIN-SALESMAN,WARD-SALESMAN


( You can also use group by Group display and merge )

MySQL:GROUP_CONCAT()


Put the result set together , Separated by commas by default , You can use [] Set up

With id grouping , hold name The value of the field is printed on one line , Comma separated ( Default )

 

1.  select id,group_concat(namefrom aa group by id;  

 

With id grouping , hold name The value of the field is printed on one line , Semicolons separate

1.  select id,group_concat(name separator ';') from aa group 

2.  by id;  

 

With id grouping , Remove redundant name The value of the field is printed on one line ,
Comma separated

Sql Code   

1.  select id,group_concat(distinct namefrom aa group by id;  





原网站

版权声明
本文为[Peach]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111630048343.html