【问题标题】:How to use query result text as another query's where condition at once?如何一次使用查询结果文本作为另一个查询的 where 条件?
【发布时间】:2022-01-23 19:45:19
【问题描述】:

在这两个表中

Table A [id, items]
        [1, "a,b,c"]

Table B [id , contents]
        ["a", apple]
        ["b", banana]

我想像查询一样立即得到 [apple,banana] 的结果

select contents from B where B.id in ("a","b","c")

或喜欢

select contents from B where B.id in (select A.items from A where id = 1)

【问题讨论】:

标签: mysql sql


【解决方案1】:

您可以使用find_in_set 函数连接这两个表:

SELECT contents
FROM   b
JOIN   a ON FIND_IN_SET(b.id, a.items) > 0
WHERE  a.id = 1

【讨论】:

  • 感谢您的快速回复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-02
  • 2021-07-03
相关资源
最近更新 更多