我試圖讓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
標記正在使用的數據庫 –