gpt4 book ai didi

php - 当没有列关系时从第二个表中检索数据

转载 作者:行者123 更新时间:2023-11-29 05:15:36 25 4
gpt4 key购买 nike

我需要一个查询来检索与特定“行业”相关的所有商店

我的 friend 设计的表没有外键和多对多关系,他用“,”分隔时使用正则表达式

TABLE shops

id | phone | address | type

1 | 11111 | XXXXX | ,10,12,13

3 | 22121 | XXXXX | ,33,37,38

5 | 11111 | XXXXX | ,51,52,55

TABLE types

ID | industry | type

10 | service | taxi

12 | service | delivery

13 | service | mail

33 | primary | electriticy

37 | primary | water

38 | primary | gas

51 | edu | primary school

52 | edu | high school

55 | edu | university

60... 70...

是否有可能在单个查询中使用 WHERE types.industry = 'service' 像 ex: 一样检索?

我很难做到这一点,虽然都是关于连接或子查询等,但我没有想出解决方案。

寻求帮助。

提前致谢

最佳答案

假设我理解正确,一种选择是使用 find_in_set()加入:

select *
from shops s
join types t on find_in_set(t.id, s.type)
where t.industry = 'service'

关于php - 当没有列关系时从第二个表中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33381666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com