开发者

concatenate string in sql

开发者 https://www.devze.com 2023-02-11 03:45 出处:网络
I have a database table \"create table t (s varchar, i int)\" with 100 records. When I want to sum all \'i\' fields, I invoke开发者_开发百科 something like \"select sum(i) fromt\". Is there a way to

I have a database table "create table t (s varchar, i int)" with 100 records.

When I want to sum all 'i' fields, I invoke开发者_开发百科 something like "select sum(i) from t". Is there a way to concatenate the 's' fields? (select concatenate(s) from t)

In any sql dialect?


In any sql dialect?

There isn't an ANSI SQL specified way to do this across all SQL dialects. If you want specific solutions for a particular DBMS, then sure, some have a ready made solution, and others have generalized solutions that are more complicated.

e.g.

  • Oracle = WM_CONCAT
  • MySQL = GROUP_CONCAT
  • SQL Server = UDF / FOR XML PATH('') / recursive CTE

You need a question for each RDBMS you need the solution for, but you will find duplicate questions for each case already on StackOverflow.

0

精彩评论

暂无评论...
验证码 换一张
取 消