我试图让AccountNumbers
在所有where
列InterestType
他们在Website
和Phone
列在其他行。如何在同一列的不同行中满足两个条件的情况下进行计数(distinct [columnname])?
现在我有以下查询:
SELECT
count(distinct c.[AccountNumber]) AS [TriangleSize]
FROM table
WHERE [InterestType] = 'Web'
我需要这个查询只能在那里,如果它有InterestType
“网络”的地方,并InterestType
“电话”的地方给定AccountNumber
只计算。
例子:
AccountNumber InterestType
001 Web
001 Phone
002 Web
002 Catalog
002 Mail
003 Phone
004 Phone
004 Web
如果这些都在数据库中的行,我理想中的查询将返回:
[TriangleSize]
2
标记正在使用的数据库 –