PostgreSQL的!
我有一张桌子"会议"
create table meeting (
id SERIAL,
name varchar,
date_start timestamp not null,
period interval default '0:0:0');
和一些数据
select * from meeting;
+----+---------------+---------------------+--------+
| id | name | date_start | period |
+----+---------------+---------------------+--------+
| 1 | Måndagsmöte | 2017-06-06 09:00:00 | 7 days |
| 2 | torsdagssoppa | 2017-06-01 00:00:00 | 7 days |
+----+---------------+---------------------+--------+
可以从中选择参加会议;
select id,name, date from meeting,
generate_series(
(select date_start::timestamptz from meeting where id=1)::timestamp,
'2017-08-01 00:00:00', (select period from meeting where id=1)) as date
where date > '2017-06-15 00:00:00'
and date < '2017-07-20 00:00:00' and id=1;
+----+-------------+---------------------+
| id | name | date |
+----+-------------+---------------------+
| 1 | Måndagsmöte | 2017-06-20 09:00:00 |
| 1 | Måndagsmöte | 2017-06-27 09:00:00 |
| 1 | Måndagsmöte | 2017-07-04 09:00:00 |
| 1 | Måndagsmöte | 2017-07-11 09:00:00 |
| 1 | Måndagsmöte | 2017-07-18 09:00:00 |
+----+-------------+---------------------+
是否有任何可能的放松&#34; id = 1&#34;并举行所有名字的会议?
/ GH
答案 0 :(得分:0)
根据您的数据,您可以使用下一个查询:
select * from (select id, name, generate_series(date_start, '2017-08-01 00:00:00', period) date from meeting) mt where mt.date > '2017-06-15 00:00:00' and mt.date < '2017-07-20 00:00:00'
id | name | date -: | :------------ | :------------------ 1 | Måndagsmöte | 2017-06-20 09:00:00 1 | Måndagsmöte | 2017-06-27 09:00:00 1 | Måndagsmöte | 2017-07-04 09:00:00 1 | Måndagsmöte | 2017-07-11 09:00:00 1 | Måndagsmöte | 2017-07-18 09:00:00 2 | torsdagssoppa | 2017-06-22 00:00:00 2 | torsdagssoppa | 2017-06-29 00:00:00 2 | torsdagssoppa | 2017-07-06 00:00:00 2 | torsdagssoppa | 2017-07-13 00:00:00
dbfiddle here