【问题标题】:How can i use two where statements before a subquery and in a subquery如何在子查询之前和子查询中使用两个 where 语句
【发布时间】:2019-11-29 12:12:54
【问题描述】:

我试图在我的 SQL 查询中使用两个 where 语句,一个查询用于过滤公司名称,另一个用于子查询。但它总是给我错误

我的代码:

select *
from products c
where c.company = "Apple"
and
where c.id in (select bi.component_id
from category ct
join items bi
on ct.id = bi.id
where ct.id in (1,2,3)
)

我只想在 Apple 上过滤,但在运行我的脚本的那一刻它给了我一个错误

【问题讨论】:

  • 你不能在这样的地方使用
  • 那我需要怎么使用呢?

标签: mysql subquery where-clause


【解决方案1】:

你有两个“哪里”,你只需要一个

select *
from products c
where c.company = "Apple"
and c.id in (select bi.component_id
from category ct
join items bi
on ct.id = bi.id
where ct.id in (1,2,3)
)

【讨论】:

    【解决方案2】:

    我觉得你应该试试 选择 * 从产品 c 其中 c.company = "苹果" 和 c.id 在哪里(选择 bi.component_id 从类别 ct 加入项目双 在 ct.id = bi.id )

    希望它对你有用

    【讨论】:

      猜你喜欢
      • 2017-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      相关资源
      最近更新 更多