使用MySQL,我可以这样做:
SELECT hobbies FROM peoples_hobbies WHERE person_id = 5;
Run Code Online (Sandbox Code Playgroud)
我的输出:
shopping
fishing
coding
Run Code Online (Sandbox Code Playgroud)
但相反,我只想要1行,1 col:
预期产出:
shopping, fishing, coding
Run Code Online (Sandbox Code Playgroud)
原因是我从多个表中选择了多个值,并且在所有连接之后我有了比我想要的更多的行.
我在MySQL Doc上寻找了一个函数,它看起来不像CONCAT或CONCAT_WS函数接受结果集,所以这里的任何人都知道如何做到这一点吗?
我想prod_replay_out根据 Postgres 中的子查询结果更新表。但是,子查询返回多行,但我想跳过这些行并根据子查询返回的单行更新表。
我已经提到链接子查询返回超过 1 行错误,但max()函数不适用于我的预期结果。您能否为我提供一些修改查询的建议?谢谢你。
prod_replay_out 有以下列:
卖家、买家、sender_tag、seller_tag、买家标签、isin、数量、in_msg_time、msg_type、cdsx_time
prod_replay_in 有以下列:
卖家、买家、sender_tag、seller_tag、买家标签、isin、数量、msg_type、cdsx_time
我尝试过什么?
请在下面找到更新sql:
更新sql:
update prod_replay_out O
set in_msg_id =
(Select id
From prod_replay_in I
Where I.msg_type = 'CDST010'
and I.seller = O.seller
and I.buyer = O.buyer
and I.sender_tag = O.sender_tag
and I.seller_tag = O.seller_tag
and I.buyer_tag = O.buyer_tag
and I.isin = O.isin
and I.quantity = O.quantity
and I.cdsx_time = O.in_msg_time
and I.cdsx_time::text like '2020-05-12%'
)
where O.msg_type = 'CDST01C'
and O.cdsx_time::text like …Run Code Online (Sandbox Code Playgroud)