![](/img/trans.png)
[英]Insert specific number of records with same column value into a different table
[英]Select from same column but multiples values and number of records with one specific value
ID Customer Status
1 ABC 1
2 ABC 2
3 ABC 3
4 ABC 1
5 PQR 1
6 PQR 2
7 PQR 3
8 XYZ 1
9 XYZ 3
我想要 select 客户同时具有值“status=1”和“Status=2”以及具有 Status=1 的同一客户的条目总数。所以结果将是,
Customer totalEntryStatus1
ABC 2
PQR 1
我怎样才能做到这一点。
谢谢 !
select Customer, count(case when status = 1 then 1 end) totalEntryStatus1
from table
where Status in (1,2)
group by Customer
having count(distinct Status) = 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.