【问题标题】:How to get product data, if the customer has non-signed products, but there are closing products如何获取产品数据,如果客户有未签约的产品,但有关闭的产品
【发布时间】:2020-10-01 02:11:17
【问题描述】:

有一个产品表有client_id和status_id字段 如何获取状态没有签名产品状态且产品状态为关闭的客户

products
  id
  client_id
  status_id

【问题讨论】:

  • 能否提供数据和预期结果?
  • 什么是标识符,如果它是封闭的或签名的?
  • id 是 status_id

标签: mysql sql select group-by having-clause


【解决方案1】:

基本上,您的问题建议使用聚合和 having 子句进行过滤。假设 status_id 1 已签名且 2 已关闭,则为:

select client_id
from products
group by client_id
having max(status_id = 1) = 0 and max(status_id = 2) = 1

【讨论】:

    猜你喜欢
    • 2012-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 2021-01-25
    • 2021-05-04
    • 1970-01-01
    相关资源
    最近更新 更多