hyz_cs 2022-07-15 10:42 采纳率: 100%
浏览 54
已结题

为什么使用另一张表的筛选结果,放到where id in ()里面,结果不对?

为什么使用另一张表的筛选结果,放到where id in ()里面,结果不对?

比如现在固定筛选,5514,5515这两个id是可以的。

mysql> select id from terminal where id in (5514,5515);
+------+
| id   |
+------+
| 5514 |
| 5515 |
+------+
2 rows in set (0.08 sec)

另一张表的某个json里面有个字段,记录的这个id表,也没问题,能查出来5514,5515

mysql> select pgrpdevlist ->> '$.devicelist' from playproject where id = 13;
+--------------------------------+
| pgrpdevlist ->> '$.devicelist' |
+--------------------------------+
| 5514,5515                      |
+--------------------------------+
1 row in set (0.06 sec)

但是两个结合起来就有问题了,只能读出来一个。

mysql> select id from terminal where id in (select pgrpdevlist ->> '$.devicelist' from playproject where id = 13);
+------+
| id   |
+------+
| 5514 |
+------+
1 row in set (0.09 sec)
  • 写回答

5条回答 默认 最新

  • 关注

    mysql> select pgrpdevlist ->> '$.devicelist' from playproject where id = 13;
    这个结果是 5514,5515 数据类型是varchar吧、
    所以mysql> select id from terminal where id in (select pgrpdevlist ->> '$.devicelist' from playproject where id = 13);
    = select id from terminal where id in (‘5514,5515’);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 8月10日
  • 已采纳回答 8月2日
  • 创建了问题 7月15日

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集