求累计工作日

这篇博客介绍了如何使用SQL查询来计算累计工作日。通过创建一个包含日期和工作状态的表格,然后利用窗口函数sum() over() 分区并按周进行累计,计算每周的工作日数量及其累计值。示例中展示了对于不同日期,如何根据一周中的日期位置来确定工作日,并展示了一种处理周末的方法。
摘要由CSDN通过智能技术生成

create table t11(
  date_id date,
  is_work int
)
insert into table t11 values('2017-07-30',0 ),
       
('2017-08-05',1),

('2017-08-04',1),
('2017-08-03',1)

select
date_id,
week_to_work,
week_sum_work,
week_sum_work-week_to_work as week_left_work
from(
    select
    date_id,
    sum(is_work) over(partition by year,week order by date_id) as week_to_work,
    sum(is_work) over(partition by year,week) as week_sum_work
    from(
        select
        date_id,
        is_work,
        year(date_id) as year,
        weekofyear(date_id) as week
        from t11
    ) ta
) tb order by date_id;


select 
 date_id
,case date_format(date_id,'u')
    when 1 then 1
    when 2 then 2 
    when 3 then 3 
    when 4 then 4
    when 5 then

1. 每天进步1%,一年的累计进步率为1.01的365次方,即1.44。每天退步1%,一年的累计剩余率为0.99的365次方,即0.69。 ```c #include <stdio.h> #include <math.h> int main() { double progress = pow(1.01, 365); double remaining = pow(0.99, 365); printf("每天进步1%%,一年的累计进步率为%.2f\n", progress); printf("每天退步1%%,一年的累计剩余率为%.2f\n", remaining); return 0; } ``` 2. 5%和1%的力量对比,写入文件中。 ```c #include <stdio.h> int main() { double power_5 = 1.05; double power_1 = 1.01; FILE *fp = fopen("power.txt", "w"); fprintf(fp, "5%%的力量和1%%的力量对比:\n"); for (int i = 1; i <= 365; i++) { fprintf(fp, "第%d天,5%%的力量为%.2f,1%%的力量为%.2f\n", i, pow(power_5, i), pow(power_1, i)); } fclose(fp); return 0; } ``` 3. 工作日的力量,一年365天,一周5个工作日,每天进步1%;一年365天,一周2个休息日,每天退步1%。 ```c #include <stdio.h> #include <math.h> int main() { double work_power = pow(1.01, 5); double rest_power = pow(0.99, 2); double power = pow(work_power * rest_power, 52); printf("工作日的力量为%.2f\n", power); return 0; } ``` 4. 工作日模式要努力到什么水平,才能与每天努力1%一样?假设一年365天,每天进步1%,不停歇;一年365天,每周工作5日休息2日,休息日下降1%。 ```c #include <stdio.h> #include <math.h> int main() { double work_power = pow(1.01, 5); double rest_power = pow(0.99, 2); double power_a = pow(1.01, 365); double power_b = pow(work_power * rest_power, 73) * pow(0.99, 104); printf("A君一年内持续每天进步1%%,不停歇的力量为%.2f\n", power_a); printf("B君一年内每周工作5日休息2日,休息日下降1%%,工作日的力量需要为%.2f才能与A君持平\n", power_a / pow(rest_power, 73) * pow(1.01, 104)); return 0; } ``` 5. A君和B君10年工作的数据对比。 ```c #include <stdio.h> #include <math.h> int main() { double power_a = 1; double power_b = 1; for (int i = 1; i <= 3650; i++) { power_a *= 1.01; power_b *= i % 7 >= 6 ? 0.99 : 1.05; if (i % 365 == 0) { printf("A君%d年持续工作的力量是%.0f,B君%d年持续工作的力量是%.0f\n", i / 365, power_a, i / 365, power_b); } } return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值