【问题标题】:SQLITE Select results into a stringSQLITE 将结果选择成字符串
【发布时间】:2015-03-31 05:23:42
【问题描述】:

我正在寻找一种将 SQLite 查询的结果作为单个字符串返回以用于内部触发器的方法。

类似于 Python 的 'somestring'.join() 方法。

Table: foo
id    |    name
1     |     "foo"
2     |     "bar"
3     |     "bro"

然后是一个select语句:

MAGIC_STRING_CONCAT_FUNCTION(SELECT id FROM foo,",");

返回 "1,2,3"

【问题讨论】:

    标签: sqlite select


    【解决方案1】:

    您正在寻找group_concat 函数:

    group_concat((SELECT id FROM foo), ",");
    

    以下是the description of the function group_concat from the documentation

    group_concat(X)group_concat(X,Y)

    group_concat() 函数返回一个字符串,它是 X 的所有非 NULL 值的串联。如果参数Y 存在 然后它用作X 实例之间的分隔符。逗号 (",") 如果省略Y,则用作分隔符。的顺序 串联的元素是任意的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-27
      • 2014-09-27
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 2018-02-17
      • 1970-01-01
      • 2022-11-16
      相关资源
      最近更新 更多