By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE accomodations (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, detail VARCHAR);
CREATE TABLE prices (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, amount DECIMAL (10, 2), accomodationId INTEGER);
CREATE TABLE depdates (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, date VARCHAR, priceId INTEGER);
INSERT INTO accomodations (id, detail) VALUES
(1, 'single room'),
(2, 'double room'),
(3, 'triple room'),
(4, 'family room'),
(5, 'child');
INSERT INTO prices (id, amount, accomodationId) VALUES
(1, 10, 1),
(2, 20, 2),
(3, 30, 3),
(4, 40, 4),
(5, 50, 5),
(6, 110, 1),
(7, 120, 2),
(8, 130, 3),
(9, 140, 4),
(10, 150, 5);
INSERT INTO depdates (id, date, priceId) VALUES
(1, '2021-01-01', 1),
(2, '2021-01-01', 2),
(3, '2021-01-01', 3),
(4, '2021-01-01', 4),
(5, '2021-01-01', 5),
(6, '2021-02-02', 6),
(7, '2021-02-02', 7),
(8, '2021-02-02', 8),
(9, '2021-02-02', 9),
(10, '2021-02-02', 10),
(11, '2021-03-03', 1),
(12, '2021-03-03', 2),
(13, '2021-03-03', 3),
(14, '2021-03-03', 4),
(15, '2021-03-03', 5);
select distinct
group_concat(distinct d.date) DepartureDates,
group_concat(group_concat(distinct a.detail || ' ' || p.amount)) over (partition by group_concat(distinct d.date)) AccomodationPrices
from accomodations a
inner join prices p on p.accomodationid = a.id
inner join depdates d on d.priceid = p.id
group by p.id
DepartureDates | AccomodationPrices |
---|---|
2021-01-01,2021-03-03 | single room 10,double room 20,triple room 30,family room 40,child 50 |
2021-02-02 | single room 110,double room 120,triple room 130,family room 140,child 150 |