根据唯一日期选择记录并计算该日期的记录数

SELECTING records based on unique date and counting how many records on that date

我有一个要简化的 table。这是它的样子:

tid     session    pos       dateOn
-----------------------------------------------
1         23        0        12/24/2020 1:00:00
2         23        1        12/24/2020 1:01:23
3         12        0        12/24/2020 1:02:43
4         23        2        12/24/2020 1:04:01
5         23        3        12/24/2020 1:04:12
6         45        0        12/26/2020 4:23:15

这个 table 告诉我,2020 年 12 月 24 日有 2 个独特的会话,12 月 26 日有 1 个。

如何编写 SQL 语句才能得到如下结果:

date             recordCount
----------------------------
12/24/2020            2
12/26/2020            1

您应该能够简单地转换为日期并汇总:

select convert(date, dateon), count(distinct session)
from t
group by convert(date, dateon)
order by convert(date, dateon);