【发布时间】:2021-01-26 23:08:02
【问题描述】:
我是 psql 的新手,想知道是否可以在查询方面获得帮助。
我有一个显示如下的当前表格:
Index ID Date Sent Tag Name Tad ID Cat
6 20306 "2020-09-18 12:02:58" "9902" "Michelle" "9902" "Servicing"
7 20510 "2020-08-27 11:23:01" "9896" "Jessica" "9896" "Servicing"
8 20582 "2020-09-21 15:24:25" "9902" "Michelle" "9902" "Servicing"
9 21196 "2020-07-22 11:42:10" "9902" "Michelle" "9902" "Servicing"
10 26548 "2020-08-03 15:16:26" "9902" "Michelle" "9902" "Servicing"
11 26924 "2020-08-28 15:49:29" "9902" "Michelle" "9902" "Servicing"
12 30310 "2020-09-24 09:44:06" "9900" "Godfrey" "9900" "Servicing"
我想知道每个人(姓名)在过去 30 天内总共有多少条记录?
我知道我当前的查询可能还没有结束,但我仍会向您展示我目前正在处理的内容:
select date_sent, Count(Distinct id) as total_leads, name from finwell_leads
group by date_sent, name
这是我希望看到的:
"2020-10-01 12:02:58" Michelle 0
"2020-10-01 12:02:58" Jessica 1
"2020-10-01 12:02:58" Godfrey 0
"2020-10-02 12:02:58" Michelle 2
"2020-10-02 12:02:58" Jessica 1
"2020-10-02 12:02:58" Godfrey 1
"2020-10-05 12:02:58" Michelle 5
"2020-10-05 12:02:58" Jessica 3
"2020-10-05 12:02:58" Godfrey 1
"2020-10-06 12:02:58" Michelle 5
"2020-10-06 12:02:58" Jessica 4
"2020-10-06 12:02:58" Godfrey 1
"2020-10-07 12:02:58" Michelle 6
"2020-10-07 12:02:58" Jessica 5
"2020-10-07 12:02:58" Godfrey 2
如何按人检索每天的累计记录?
谢谢!
【问题讨论】:
标签: sql postgresql datetime count left-join