甲骨文按客户和日期分组
Oracle group by client and date
我有一个有效的休闲查询:
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
它产生的结果如下:
Candidates| Clients
2 | client 1
4 | cleint 2
56 | client whatever..
我将如何着手在给定日期范围内按天和客户细分候选人数量?所以它会显示那天,没有候选人,客户
这是你想要的吗?
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
我有一个有效的休闲查询:
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
它产生的结果如下:
Candidates| Clients
2 | client 1
4 | cleint 2
56 | client whatever..
我将如何着手在给定日期范围内按天和客户细分候选人数量?所以它会显示那天,没有候选人,客户
这是你想要的吗?
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