corrected view for calculation of camp beds, see #12

This commit is contained in:
Jottyfan 2024-03-07 21:02:11 +01:00
parent f467d21d53
commit 30e07c4bc7
5 changed files with 45 additions and 81 deletions

View File

@ -22,7 +22,7 @@ apply plugin: 'java'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
group = 'de.jottyfan' group = 'de.jottyfan'
version = '2024.02.23' version = '2024.03.07'
description = """COJooq""" description = """COJooq"""

View File

@ -1,47 +0,0 @@
begin;
alter table camp.t_camp add column beds_male integer not null default 0;
alter table camp.t_camp add column beds_female integer not null default 0;
alter table camp.t_camp add column blocked_beds_male integer not null default 0;
alter table camp.t_camp add column blocked_beds_female integer not null default 0;
create or replace view camp.v_camp as
select c.pk,
(c.depart < now()) as is_over,
c.name,
c.arrive,
c.depart,
date_part('isoyear'::text, c.arrive) as year,
l.name as location_name,
c.min_age,
c.max_age,
l.url,
c.price,
c.countries,
c.fk_document,
c.beds_female,
c.beds_male,
c.blocked_beds_female,
c.blocked_beds_male,
count(mp.pk) as used_beds_male,
count(fp.pk) as used_beds_female
from camp.t_camp c
left join camp.t_location l on c.fk_location = l.pk
left join camp.t_person mp on mp.fk_camp = c.pk
and mp.accept = true
and mp.sex = 'male'::camp.enum_sex
and mp.camprole = 'student'::camp.enum_camprole
left join camp.t_person fp on fp.fk_camp = c.pk
and fp.accept = true
and fp.sex = 'female'::camp.enum_sex
and fp.camprole = 'student'::camp.enum_camprole
group by c.pk, c.depart, c.name, c.arrive, l.name, c.min_age, c.max_age, l.url, c.price, c.countries,
c.fk_document, c.beds_female, c.beds_male, c.blocked_beds_female, c.blocked_beds_male;
create or replace view camp.v_version as
select '2024.02'::text as version;
drop schema public;
alter schema camp rename to public;
commit;

View File

@ -0,0 +1,6 @@
begin;
\i views/camp.sql
\i views/version.sql
commit;

View File

@ -1,5 +1,19 @@
create view public.v_camp as create or replace view public.v_camp as
select c.pk, with fbeds(used_beds_female, fk_camp) as (
select count(1), fk_camp
from t_person
where accept = true
and sex = 'female'
and camprole = 'student'
group by fk_camp
), mbeds(used_beds_male, fk_camp) as (
select count(1), fk_camp
from t_person
where accept = true
and sex = 'male'
and camprole = 'student'
group by fk_camp
) select c.pk,
(c.depart < now()) as is_over, (c.depart < now()) as is_over,
c.name, c.name,
c.arrive, c.arrive,
@ -16,18 +30,9 @@ select c.pk,
c.beds_male, c.beds_male,
c.blocked_beds_female, c.blocked_beds_female,
c.blocked_beds_male, c.blocked_beds_male,
count(mp.pk) as used_beds_male, mbeds.used_beds_male,
count(fp.pk) as used_beds_female fbeds.used_beds_female
from public.t_camp c from public.t_camp c
left join public.t_location l on c.fk_location = l.pk left join public.t_location l on c.fk_location = l.pk
left join public.t_person mp on mp.fk_camp = c.pk left join mbeds on mbeds.fk_camp = c.pk
and mp.accept = true left join fbeds on fbeds.fk_camp = c.pk;
and mp.sex = 'male'::enum_sex
and mp.camprole = 'student'::enum_camprole
left join public.t_person fp on fp.fk_camp = c.pk
and fp.accept = true
and fp.sex = 'female'::enum_sex
and fp.camprole = 'student'::enum_camprole
group by c.pk, c.depart, c.name, c.arrive, l.name, c.min_age, c.max_age, l.url, c.price, c.countries,
c.fk_document, c.beds_female, c.beds_male, c.blocked_beds_female, c.blocked_beds_male;

View File

@ -1,2 +1,2 @@
create view public.v_version as create or replace view public.v_version as
select '2024.02'::text as version; select '2024.03.07'::text as version;