Oracle group by client and date

33 Views Asked by At

I have the fallowing query which works:

SELECT count(cand_id) as candidates, SB.client_id as client
            FROM REPLIES r
            JOIN clients sb on sb.main_acc_id = r.acc_id
            where reply_dt >= TO_DATE('2021-02-08 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
            AND reply_dt <= TO_DATE('2021-02-15 23:59:59', 'YYYY-MM-DD HH24:MI:SS')
            AND sb.status = 'A'
            GROUP BY client_id

It produces results like:

 Candidates| Clients
     2     |  client 1
     4     |  cleint 2
    56     |  client whatever..  

How would I go about breaking down the number of candidates down by Day and Client over the given date range? So it would show the day, no candidates, client

1

There are 1 best solutions below

2
Gordon Linoff On BEST ANSWER

Does this do what you want?

SELECT TRUNC(r.reply_dt), sb.client_id, COUNT(cand_id) as candidates
FROM REPLIES r JOIN
     clients sb 
     ON sb.main_acc_id = r.acc_id
WHERE sb.status = 'A'
GROUP BY TRUNC(r.reply_dt), client_id