Postgresql!
I have a table "meeting"
create table meeting (
id SERIAL,
name varchar,
date_start timestamp not null,
period interval default '0:0:0');
And some data
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 |
+----+---------------+---------------------+--------+
And can select comming meetings from this;
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 |
+----+-------------+---------------------+
Is there any posibility to relax the "id=1" and have all meetings for all names?
/gh
According to your data you can use the next query:
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'
\nid | name | date \n-: | :------------ | :------------------ \n 1 | Måndagsmöte | 2017-06-20 09:00:00 \n 1 | Måndagsmöte | 2017-06-27 09:00:00 \n 1 | Måndagsmöte | 2017-07-04 09:00:00 \n 1 | Måndagsmöte | 2017-07-11 09:00:00 \n 1 | Måndagsmöte | 2017-07-18 09:00:00 \n 2 | torsdagssoppa | 2017-06-22 00:00:00 \n 2 | torsdagssoppa | 2017-06-29 00:00:00 \n 2 | torsdagssoppa | 2017-07-06 00:00:00 \n 2 | torsdagssoppa | 2017-07-13 00:00:00 \n
dbfiddle here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.