简体   繁体   English

Select 来自同一列,但多个值和具有一个特定值的记录数

[英]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

I want to select customer who has both values "status=1" and "Status=2' and also total number of entry of same customer with Status=1. So the result will be,我想要 select 客户同时具有值“status=1”和“Status=2”以及具有 Status=1 的同一客户的条目总数。所以结果将是,

Customer   totalEntryStatus1
ABC        2
PQR        1

How can I do this.我怎样才能做到这一点。

Thankyou !谢谢 !

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.

相关问题 将具有相同列值的特定数量的记录插入到另一个表中 - Insert specific number of records with same column value into a different table 在SQL中更改一个列值的情况下多次选择同一记录 - select same records multiple times with one column value changed in SQL 从一列中选择在其他列中具有相同值的所有不同记录 - Select all different records from one column that have the same value in other coumn 根据同一表中的列值从表中选择记录 - Select records from a table based on column value from same table 从联接的表中,选择一列的最大值,但是如果有多个maxes,则从另一列中选择具有最大值的那个。 - from a joined table, select the max value of a column, but if there are multiples maxes, pick the one that has the max value from another column SQL选择同一列中具有不同值的记录 - SQL select records with different values in same column 如何通过比较列A中具有相同值的记录中的列B,C中的值来选择记录? - How do I select records by comparing values in columns B, C among records with same value in column A? 从多个表中选择唯一值,其中一个表具有多个 - Select Distinct Value from Multiple tables, Where One has Multiples 从同一列中选择具有特定多个值的行? - Select rows with specific multiple values from the same column? 从一列中选择共享另一列中的值的值 - Select values from one column which share a value in another column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM