mysql - 如何更新具有彼此串联的多行的列

标签 mysql sql sas

我正在 SAS 平台上工作,我有一个对象表,另一个表保存针对该对象的注释。一个对象可以有多个注释。作为

object
 ID | Name | Other Attributes 
  1    obj       ...  

Comment
ID | Comment | object_ID | type
 1    first       1        custom
 2    Second      1        custom

我想创建一个cast_comm表,其单行中有逗号分隔的评论

proc sql noprint;
create table cast_comm as
select distinct O.ID,C.Comment
from Comments as C, Object as O
where O.ID = C.Object_ID
and C.type = "custom"
quit;

我想要表格为

cast_comm
ID | Comments
 1    First, Second

各位,我应该用什么方法来做到这一点?感谢您的支持。

最佳答案

在 proc sql 中没有可使用的组 concat; 您可以在连接后使用数据步骤:

data cast_comm_concat;
    set cast_comm;
by id; /*make sure it's sorted*/
length comments $ 1000 ;
retain comments;

if (first.id) then do;
   comments="";
end;

comments=catx(",",comments,comment);

if last.id then do;
    output;
end;

run;

关于mysql - 如何更新具有彼此串联的多行的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48396627/

相关文章:

sql - 在窗口函数内过滤(通过...分区)?

sas - 将带空格的字符串转换为有效的表名

SAS 解压缩单个 sas7bdat 文件

sas - 在 PROC FCMP 中散列数据时没有保证的 libname

c# - 如果值已更改 C#,则将参数从文本框发送到存储过程

mysql - 为什么我不能插入到同一个表上的触发器调用的 SP 中的表中?

mysql - ActiveRecord::StatementInvalid: Mysql2::Error: 无法创建数据库 'sharetribe_development' (errno: 2)

PHP - 导出 CSV 函数转到空白页

Mysql - 查询包括求和和内连接

sql - 从 SQL Server 中的字符串中提取子字符串