gpt4 book ai didi

MySQL查询获取连接表B的计数小于表A中特定字段的值

转载 作者:行者123 更新时间:2023-11-29 12:06:15 24 4
gpt4 key购买 nike

我正在努力处理 MyQSL 查询。我有两张 table :

引用

  • ID
  • service_provider
  • 报价金额
  • required_repairs_id

所需维修

  • ID
  • repair_description
  • quotes_required

表“required_repairs”通过“required_repairs_id”字段连接到表“quotes”。

因此,当需要进行新的维修时,“required_repairs”表中会输入一个新行,其中包含维修说明以及需要服务提供商提供的最低报价。然后,当从服务提供商处收到报价时,它们会被输入到报价表中,并带有相应的维修 ID。

我需要创建一个 MySQL 查询,该查询将返回没有足够报价的修复数量。即,报价少于该维修所需的维修数量。

我真的很苦恼这个问题,如果有人能帮助我,我将不胜感激。

提前致谢...

最佳答案

select count(r.id)
from required_repairs r
join
(
select required_repairs_id , count(id) as q_count
from quotes
group by required_repairs_id
) q on q.required_repairs_id = r.id
where q.q_count < r.quotes_required

关于MySQL查询获取连接表B的计数小于表A中特定字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31427302/

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