开发者

concatenate string in sql

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜