大佬教程收集整理的这篇文章主要介绍了在每个月开始之前获取所有条目的 col 计数,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
给定一个具有两个特征的数据集:ID 和 created_at(日期)。对于数据集中包含的所有月份,获取每个月开始之前创建的所有 ID 总和的最佳方法是什么?例如,2021 年 5 月的值必须是在 2021 年 4 月或更早创建的所有 ID 的计数
类似于:
function submitForm(formElement,funcToRun) {
if (Formchecks()) {
var fd = new FormData(formElement);
CallhttpHandler(formElement.action,funcToRun,fd);
}
}
function Formchecks() {
var errors = []
var @R_262_5747@d = document.getElementByID("input_password");
if (/[^a-z0-9]/i.test(@R_262_5747@d.value)) {
errors.push("*@R_262_5747@d must only be A-Z,a-z or 0-9")
}
//one example of the checks,there are like 20
if (errors.length > 0) {
errorElement.INNERHTML = errors.join(',')
console.log(errors)
return false
}
return true
}
}
您可以在计算每月总计后使用窗口函数,如下所示: 示例表:
create table test (id int,created_at datE);
insert into test values(1,'2021-06-13');
insert into test values(2,'2021-01-13');
insert into test values(3,'2021-02-13');
insert into test values(4,'2021-02-13');
第 1 步:计算每月明智的计数:
SELEct date_trunc('month',created_at) "month_",count(*) "count_" from test
第 2 步:使用总和窗口函数计算上述查询结果上月份的总和。
查询
SELEct
extract(year from month_) "Year",extract(month from month_) "Month",coalesce(sum(count_) over (order by month_ rows between UNBOUNDED preceding and 1 preceding),0) "Count"
from (
SELEct date_trunc('month',count(*) "count_" from test
group by 1) t1
输出:
Year Month Count
2021 1 0
2021 2 1
2021 6 3
DEMO
以上是大佬教程为你收集整理的在每个月开始之前获取所有条目的 col 计数全部内容,希望文章能够帮你解决在每个月开始之前获取所有条目的 col 计数所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。