【发布时间】:2020-12-02 07:47:37
【问题描述】:
我的数据是这样的
Count years
1 2020-08-11
1 2020-07-11
1 2019-09-01
1 2019-08-16
1 2019-05-04
1 2018-06-11
我正在编写一个查询,我必须在其中找到例如
我这样写了查询:
with sum_count as(
select count(*) as 'Counts', years from [practice].[dbo].[People]
where years<='2019-05-04'
group by years)
select sum(Counts) + 1 as Sum
from sum_count
您能否帮助对所有日期(例如 2020-08-11)做同样的事情 计数应为 5,总和为 6
【问题讨论】:
-
请指定哪个 DBMS。
-
嗨 nifriz 我正在 sql server 中编写查询
标签: sql sql-server sum