1 Upvote

SQL generate_series, dayofweek(DOW), weekday, functions

SQL
Querying

https://www.codewars.com/kata/58241d05e7a162c5b100010f/train/sql

-- Replace with your code
CREATE OR REPLACE FUNCTION weekdays(DATE,DATE)
  RETURNS INTEGER AS
$func$
SELECT COUNT(*)
FROM GENERATE_SERIES(LEAST($1,$2),GREATEST($1,$2),'1d') AS days
WHERE EXTRACT(ISODOW FROM days) < 6
$func$
LANGUAGE sql;

By changjulian17 - Last Updated Dec. 23, 2021, 2:02 p.m.

Did you find this snippet useful?

Sign up to bookmark this in your snippet library

COMMENTS
RELATED SNIPPETS
left join LATERAL
SQL
Querying

2
median
SQL
Querying

2
SQL creating a view
SQL
Querying

1
SQL window function
SQL
Querying

1
SQL RANK
SQL
Querying

1
EXISTS
SQL
Querying

1
Top Contributors
103
100