【问题标题】:Retrieve data from second table when there is no column relations没有列关系时从第二个表中检索数据
【发布时间】:2015-10-28 02:00:37
【问题描述】:

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

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

餐桌店

标识 |电话 |地址 |输入

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

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

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

表格类型

ID |工业 |输入

10 |服务 |出租车

12 |服务 |发货

13 |服务 |邮件

33 |初级 |电力

37 |初级 |水

38 |初级 |气体

51 |教育 |小学

52 |教育 |高中

55 |教育 |大学

60... 70...

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

我在做这件事时遇到了麻烦,虽然都是关于联接或子查询等,但我想不出任何解决方案。

寻求帮助。

提前致谢

【问题讨论】:

    标签: php mysql regex


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-07
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      相关资源
      最近更新 更多