Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
postgresql: working days
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
--PostgreSQL 9.5 --'\\' is a delimiter ---create table create table orderT ( id integer PRIMARY KEY, country_code varchar(2), created_date date, closed_date date ); ---populate table INSERT INTO orderT VALUES (1, 'US', '2017-03-03'::date, '2017-03-03'::date + interval '1 day' * 21); INSERT INTO orderT VALUES (2, 'CA', '2017-03-03'::date, '2017-03-03'::date + interval '1 day' * 35); SELECT h.id, count(*) as wkday FROM ( SELECT t.id, max(created_date) as createddt, max(closed_date) as closeddt FROM orderT t group by t.id ) h , generate_series(h.createddt, h.closeddt, interval '1 day') i where extract(dow from i::date) between 1 and 5 group by h.id;
absolute service time: 0,44 sec
edit mode
|
history
|
discussion
wkday
1
40