Skip to content

Commit e28ba12

Browse files
authored
Create date.sql
1 parent 5fae974 commit e28ba12

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

pgexercises/date.sql

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
select timestamp '2012-08-31 01:00:00'
2+
3+
4+
select timestamp '2012-08-31 01:00:00' - timestamp'2012-07-30 01:00:00' as interval;
5+
6+
7+
select generate_series(
8+
(date '2012-10-01')::timestamp,
9+
(date '2012-10-31')::timestamp,
10+
interval '1 day'
11+
);
12+
13+
14+
15+
select extract (day from date(timestamp '2012-08-31') ) as date_part
16+
17+
select extract(epoch from (timestamp '2012-09-02 00:00:00' - timestamp '2012-08-31 01:00:00')) as t;
18+
19+
20+
select extract(month from cal.month) as month,
21+
(cal.month + interval '1 month') - cal.month as length
22+
from
23+
(
24+
select generate_series(timestamp '2012-01-01', timestamp '2012-12-01', interval '1 month') as month
25+
) cal
26+
order by month;
27+
28+
29+
select (date_trunc('month',ts.testts) + interval '1 month')
30+
- date_trunc('day', ts.testts) as remaining
31+
from (select timestamp '2012-02-11 01:00:00' as testts) ts
32+
33+
34+
35+
select
36+
37+
starttime,
38+
39+
starttime + slots* (interval '30 minutes') as endtime
40+
41+
from cd.bookings
42+
order by endtime desc ,starttime desc limit 10
43+
44+
45+
46+
select
47+
48+
date_trunc('month' , starttime) as month,
49+
count(facid)
50+
from cd.bookings
51+
group by date_trunc('month' , starttime)
52+
order by date_trunc('month' , starttime)
53+
54+
select name, month,
55+
round((100*slots)/
56+
cast(
57+
25*(cast((month + interval '1 month') as date)
58+
- cast (month as date)) as numeric),1) as utilisation
59+
from (
60+
select facs.name as name, date_trunc('month', starttime) as month, sum(slots) as slots
61+
from cd.bookings bks
62+
inner join cd.facilities facs
63+
on bks.facid = facs.facid
64+
group by facs.facid, month
65+
) as inn
66+
order by name, month

0 commit comments

Comments
 (0)