University stuff.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

timelistedb.sql 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. drop view if exists Timeantall;
  2. drop view if exists Varighet;
  3. drop table if exists Timelistelinje;
  4. drop table if exists Timeliste;
  5. create table Timeliste (
  6. timelistenr int primary key,
  7. status text not null,
  8. levert date,
  9. utbetalt date,
  10. beskrivelse text not null,
  11. check (status = 'aktiv' or status = 'levert' or status = 'utbetalt')
  12. );
  13. create table Timelistelinje (
  14. timelistenr int references Timeliste(timelistenr),
  15. linjenr int,
  16. startdato date not null,
  17. starttid time not null,
  18. sluttid time,
  19. pause int,
  20. beskrivelse text not null,
  21. primary key (timelistenr, linjenr)
  22. );
  23. create view Varighet AS
  24. select timelistenr,
  25. linjenr,
  26. (sluttid - starttid - pause) as varighet
  27. from (select timelistenr,
  28. linjenr,
  29. cast(extract(hour from starttid) as integer)*60 +
  30. cast(extract(minute from starttid) as integer) as starttid,
  31. cast(extract(hour from sluttid) as integer)*60 +
  32. cast(extract(minute from sluttid) as integer) +
  33. case when sluttid < starttid then 60*24
  34. else 0
  35. end as sluttid,
  36. case when pause is null then 0
  37. else pause
  38. end as pause
  39. from Timelistelinje
  40. where sluttid is not null) as c;
  41. create view Timeantall AS
  42. select timelistenr, ceil(cast(minuttantall as real)/60) as timeantall
  43. from (select timelistenr, sum(varighet) as minuttantall
  44. from Varighet
  45. group by timelistenr) as m;
  46. \copy Timeliste from 'timeliste.txt' with delimiter '|' null ''
  47. \copy Timelistelinje from 'timelistelinje.txt' with delimiter '|' null ''