Mysql 仅选择与条件匹配的值
我有以下(示例)表格: 其目的是仅选择活跃客户。假设和条件如下:Mysql 仅选择与条件匹配的值,mysql,business-intelligence,Mysql,Business Intelligence,我有以下(示例)表格: 其目的是仅选择活跃客户。假设和条件如下: 一个客户可以有多个订阅 活动客户=至少有一个活动订阅的客户 活动订阅的时间为:Status=Active,开始日期为>=sysdate(),没有结束日期 我将有一个非常长的状态列表,可以使用CASE语句映射这些状态。有没有办法根据这个例子选择不同的活跃客户?我是一个乞丐,不知道如何开始这项任务 谢谢,Pawel您对活跃客户的条件可以这样写: status = 'Active' and start_date >= curdat
谢谢,Pawel您对活跃客户的条件可以这样写:
status = 'Active' and start_date >= curdate() and end_date is null
因此,按客户分组
,并使用having
子句中的条件:
select customer
from tablename
group by customer
having sum(status = 'Active' and start_date >= curdate() and end_date is null)
如果sum()
在任何其他情况下,它的评估结果都是true
通过上的基本文章,您将能够自己解决此问题并了解更多信息。您能否提供您的表结构。您好,我认为它对我有用。多谢了,波沃
select customer
from tablename
group by customer
having sum(status = 'Active' and start_date >= curdate() and end_date is null)