基本上,我想知道 Excel 的 COUNTIF(Range,Criteria) 的 SQL 等效项
我想要这个输出
CALL ID | Name | Phone Number | # of Occurrences
0001 | Name1 | 0000000000 | 2
0002 | Name2 | 1111111111 | 1
0003 | Name1 | 0000000000 | 2
0004 | Name3 | 2222222222 | 2
0005 | Name5 | 4444444444 | 1
0006 | Name4 | 3333333333 | 1
0007 | Name3 | 2222222222 | 2
不是这个输出
CALL ID | Name | Phone Number | # of Occurrences
0001 | Name1 | 0000000000 | 2
0002 | Name2 | 1111111111 | 1
0004 | Name3 | 2222222222 | 2
0005 | Name5 | 4444444444 | 1
0006 | Name4 | 3333333333 | 1
这是一个简化的表格。这是我的复杂表,这是结果 结果
我想要的是避免有 2 个约会,而是将它们列在单独的行中,以便约会只有 1
这是查询
SELECT
a."Call ID" as "Call ID",
CONCAT(a.Campaign, '-', a."CONTACT ID") as IDENTIFIER,
REPLACE(a."Campaign",'CW-','') as "Campaign",
a."DNIS" as "DNIS",
a."CONTACT ID" as "CONTACT ID",
a."first_name" as "first_name",
a."last_name" as "last_name",
a."city" as "city",
a."street" as "street",
a."zip" as "zip",
a."state" as "state",
a."number2" as "number2",
a."number1" as "number1",
a."Customer ID - real" as "Customer ID - real",
COUNT(a."Call ID") as "Dial Attempts"
FROM "Five9 Calls" a
group by
CONCAT(a.Campaign, '-', a."CONTACT ID"),
REPLACE(a."Campaign",'CW-',''),
a."CONTACT ID",
a."first_name",
a."last_name",
a."city",
a."street",
a."zip",
a."state",
a."number2",
a."number1"