计算工作日(不包括星期日)

时间:2017-07-31 15:32:55

标签: postgresql

SELECT DATE_PART('DAY',"repairClose"-"createdOn")::INTEGER as "noOfDays"
FROM "mstRecord"
WHERE "repairClose" is not null

我尝试了上面的查询,它返回包括星期日的结果。我希望结果排除星期日。

3 个答案:

答案 0 :(得分:0)

尝试使用extract(dow from "column") <> 0

这是一个例子:

t=# with dates as (select generate_series(now(),now()+'3 weeks'::interval,'1 day'::interval) "repairClose", now() "createdOn")
select "repairClose"-"createdOn","repairClose"::date, "createdOn"::date 
from dates 
where extract(dow from "repairClose") <> 0;
 ?column? | repairClose | createdOn  
----------+-------------+------------
 00:00:00 | 2017-07-31  | 2017-07-31
 1 day    | 2017-08-01  | 2017-07-31
 2 days   | 2017-08-02  | 2017-07-31
 3 days   | 2017-08-03  | 2017-07-31
 4 days   | 2017-08-04  | 2017-07-31
 5 days   | 2017-08-05  | 2017-07-31
 7 days   | 2017-08-07  | 2017-07-31
 8 days   | 2017-08-08  | 2017-07-31
 9 days   | 2017-08-09  | 2017-07-31
 10 days  | 2017-08-10  | 2017-07-31
 11 days  | 2017-08-11  | 2017-07-31
 12 days  | 2017-08-12  | 2017-07-31
 14 days  | 2017-08-14  | 2017-07-31
 15 days  | 2017-08-15  | 2017-07-31
 16 days  | 2017-08-16  | 2017-07-31
 17 days  | 2017-08-17  | 2017-07-31
 18 days  | 2017-08-18  | 2017-07-31
 19 days  | 2017-08-19  | 2017-07-31
 21 days  | 2017-08-21  | 2017-07-31
(19 rows)

答案 1 :(得分:0)

import java.util.Scanner;

public class DecreasingOrNot {

    public static void main(String[] args){
        int number1, number2;
        boolean decrease = true;
        Scanner input = new Scanner(System.in);
        System.out.println("Enter a sequence of numbers: ");
        number2 = input.nextInt();
        while (decrease && input.hasNext()){
            number1 = number2;
            number2 = input.nextInt();
            if (number1 < number2){
                decrease = false;
            }
        }
        if (decrease){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

答案 2 :(得分:0)

选择 (SELECT count(*)AS count_days_no_weekend FROM generate_series(“createdOn”:: date,“repairClose”:: date,'1 day')d(the_day) 提取物('ISODOW' FROM the_day)&lt; 7)作为“no_of_days” 来自“mstRecord”,其中“repairClose”不为null 按“no_of_days”排序

在postgres中,将“isodow”选项添加到EXTRACT(),其中Sunday = 7,Monday = 1,Tuesday = 2,依此类推。