查询仅在多个行满足特定条件时显示

时间:2013-12-06 14:43:48

标签: mysql

我有一个表格,用于存储客户的约会,有多个点数可以持续数周,客户可能会也可能不会完成所有的点数。

让我们这样说:

apointment_order(PrimaryKey) 
Line(PrimaryKey) 
Customer_id 
Date  
Apointment_Type   
Apointment_Status

我有4种不同的约会类型(第1次会议,第2次会议...... ) 和两个状态(已完成,未完成

我需要帮助设计一个只能获得约会_订单的查询 该订单中的所有约会类型均为已完成状态。

例如,如果约会订单有4个约会类型且只有3个已完成状态,则它不应出现在结果中。

我的目标是了解完成所有会议的所有客户(1-4)。

1 个答案:

答案 0 :(得分:0)

以下是一种方法,使用group byhaving

select a.apointment_order
from appointments a
group by a.apointment_order
having count(a.Apointment_Type = 'Completed') = count(*);
相关问题