Basically, I want to know the SQL Equivalent of Excel's COUNTIF(Range,Criteria)
I want this Output
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
NOT This Output
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
This is a simplified table. This is my complex table and this is the result
Result
What i wanted is to avoid having 2 Appointments, instead, list them in separate rows so that the appointment is only 1
Here is the query
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"