Erweitere die Datenbank
This commit is contained in:
+74
-57
@@ -22,14 +22,17 @@ DROP TABLE IF EXISTS public."Arbeitszeiten";
|
||||
-- Name: Arbeitszeiten; Type: TABLE; Schema: public; Owner: torsten
|
||||
--
|
||||
|
||||
CREATE TABLE public."Arbeitszeiten" (
|
||||
CREATE TABLE public."Arbeitszeiten"
|
||||
(
|
||||
"Datum" date not null,
|
||||
"Arbeitszeit" interval(6) null,
|
||||
"HomeOffice" boolean default FALSE not null,
|
||||
constraint "Arbeitszeiten_pkey" primary key ("Datum")
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."Arbeitszeiten" OWNER TO bruce;
|
||||
ALTER TABLE public."Arbeitszeiten"
|
||||
OWNER TO bruce;
|
||||
|
||||
--
|
||||
-- Name: Arbeitszeiten - Jahr; Type: VIEW; Schema: public; Owner: torsten
|
||||
@@ -37,54 +40,65 @@ ALTER TABLE public."Arbeitszeiten" OWNER TO bruce;
|
||||
|
||||
CREATE OR REPLACE VIEW public."Arbeitszeiten - Jahr" AS
|
||||
SELECT (date_part('year'::text, "Arbeitszeiten"."Datum"))::text AS "Jahr",
|
||||
sum("Arbeitszeiten"."Arbeitszeit") AS "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum") AS "Arbeitstage",
|
||||
(sum("Arbeitszeiten"."Arbeitszeit") - ((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden"
|
||||
sum("Arbeitszeiten"."Arbeitszeit")::interval AS "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum")::bigint AS "Arbeitstage",
|
||||
(sum("Arbeitszeiten"."Arbeitszeit") -
|
||||
((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden",
|
||||
(count(*) filter (where "Arbeitszeiten"."HomeOffice"))::int as "Home-Office-Tage"
|
||||
FROM public."Arbeitszeiten"
|
||||
GROUP BY (date_part('year'::text, "Arbeitszeiten"."Datum"))
|
||||
ORDER BY (date_part('year'::text, "Arbeitszeiten"."Datum"));
|
||||
|
||||
|
||||
ALTER TABLE public."Arbeitszeiten - Jahr" OWNER TO bruce;
|
||||
ALTER TABLE public."Arbeitszeiten - Jahr"
|
||||
OWNER TO bruce;
|
||||
|
||||
--
|
||||
-- Name: Arbeitszeiten - Monat; Type: VIEW; Schema: public; Owner: torsten
|
||||
--
|
||||
|
||||
CREATE OR REPLACE VIEW public."Arbeitszeiten - Monat" AS
|
||||
SELECT to_char(date_trunc('month'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone), 'TMYYYY TMMonth'::text) AS "Monat",
|
||||
sum("Arbeitszeiten"."Arbeitszeit") AS "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum") AS "Arbeitstage",
|
||||
(sum("Arbeitszeiten"."Arbeitszeit") - ((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden"
|
||||
SELECT to_char(date_trunc('month'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone),
|
||||
'TMYYYY TMMonth'::text) AS "Monat",
|
||||
sum("Arbeitszeiten"."Arbeitszeit")::interval AS "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum")::bigint AS "Arbeitstage",
|
||||
(sum("Arbeitszeiten"."Arbeitszeit") -
|
||||
((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden",
|
||||
(count(*) filter (where "Arbeitszeiten"."HomeOffice"))::int as "Home-Office-Tage"
|
||||
FROM public."Arbeitszeiten"
|
||||
GROUP BY (date_trunc('month'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone))
|
||||
ORDER BY (date_trunc('month'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone));
|
||||
|
||||
|
||||
ALTER TABLE public."Arbeitszeiten - Monat" OWNER TO bruce;
|
||||
ALTER TABLE public."Arbeitszeiten - Monat"
|
||||
OWNER TO bruce;
|
||||
|
||||
--
|
||||
-- Name: Arbeitszeiten - Woche; Type: VIEW; Schema: public; Owner: torsten
|
||||
--
|
||||
|
||||
CREATE OR REPLACE VIEW public."Arbeitszeiten - Woche" AS
|
||||
SELECT to_char(date_trunc('week'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone), 'TMYYYY#WW'::text) AS "Woche",
|
||||
sum("Arbeitszeiten"."Arbeitszeit") AS "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum") AS "Arbeitstage",
|
||||
(sum("Arbeitszeiten"."Arbeitszeit") - ((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden"
|
||||
SELECT to_char(date_trunc('week'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone),
|
||||
'TMYYYY#WW'::text) AS "Woche",
|
||||
sum("Arbeitszeiten"."Arbeitszeit")::interval AS "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum")::bigint AS "Arbeitstage",
|
||||
(sum("Arbeitszeiten"."Arbeitszeit") -
|
||||
((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden",
|
||||
(count(*) filter (where "Arbeitszeiten"."HomeOffice"))::int as "Home-Office-Tage"
|
||||
FROM public."Arbeitszeiten"
|
||||
GROUP BY (date_trunc('week'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone))
|
||||
ORDER BY (date_trunc('week'::text, ("Arbeitszeiten"."Datum")::timestamp with time zone));
|
||||
|
||||
|
||||
ALTER TABLE public."Arbeitszeiten - Woche" OWNER TO bruce;
|
||||
ALTER TABLE public."Arbeitszeiten - Woche"
|
||||
OWNER TO bruce;
|
||||
|
||||
--
|
||||
-- Data for Name: Arbeitszeiten; Type: TABLE DATA; Schema: public; Owner: torsten
|
||||
--
|
||||
|
||||
INSERT INTO public."Arbeitszeiten" ("Datum", "Arbeitszeit") VALUES
|
||||
('2020-01-07','08:06:00'),
|
||||
INSERT INTO public."Arbeitszeiten" ("Datum", "Arbeitszeit")
|
||||
VALUES ('2020-01-07', '08:06:00'),
|
||||
('2020-01-08', '08:16:00'),
|
||||
('2020-01-09', '07:49:00'),
|
||||
('2020-01-10', '07:30:00'),
|
||||
@@ -106,43 +120,46 @@ INSERT INTO public."Arbeitszeiten" ("Datum", "Arbeitszeit") VALUES
|
||||
('2020-02-03', '07:56:00'),
|
||||
('2020-02-04', '08:05:00'),
|
||||
('2020-02-05', '07:58:00'),
|
||||
('2020-02-06','08:01:00'),
|
||||
('2020-02-07','07:59:00'),
|
||||
('2020-02-10','07:50:00'),
|
||||
('2020-02-11','08:01:00'),
|
||||
('2020-02-12','08:14:00'),
|
||||
('2020-02-13','08:12:00'),
|
||||
('2020-02-14','07:51:00'),
|
||||
('2020-02-17','07:59:00'),
|
||||
('2020-02-18','08:05:00'),
|
||||
('2020-02-19','07:34:00'),
|
||||
('2020-02-20','07:33:00'),
|
||||
('2020-02-21','07:56:00'),
|
||||
('2020-02-24','08:02:00'),
|
||||
('2020-02-25','08:13:00'),
|
||||
('2020-02-26','08:42:00'),
|
||||
('2020-02-27','07:49:00'),
|
||||
('2020-02-28','08:16:00'),
|
||||
('2020-03-02','08:22:00'),
|
||||
('2020-03-03','08:20:00'),
|
||||
('2020-03-04','08:12:00'),
|
||||
('2020-03-05','08:32:00'),
|
||||
('2020-03-06','04:41:00'),
|
||||
('2020-03-09','07:05:00'),
|
||||
('2020-03-10','07:34:00'),
|
||||
('2020-03-11','07:39:00'),
|
||||
('2020-03-12','07:50:00'),
|
||||
('2020-03-13','08:26:00'),
|
||||
('2020-03-16','07:51:00'),
|
||||
('2020-03-17','07:50:00'),
|
||||
('2020-03-18','07:19:00'),
|
||||
('2020-03-19','07:55:00'),
|
||||
('2020-03-20','05:43:00'),
|
||||
('2020-03-23','08:05:00'),
|
||||
('2020-03-24','08:21:00'),
|
||||
('2020-03-25','08:10:00'),
|
||||
('2020-03-26','10:31:00'),
|
||||
('2020-03-27','04:55:00'),
|
||||
('2020-03-30','08:21:00'),
|
||||
('2020-03-31','08:01:00')
|
||||
('2020-02-06', '08:01:00')
|
||||
;
|
||||
|
||||
INSERT INTO public."Arbeitszeiten" ("Datum", "Arbeitszeit", "HomeOffice")
|
||||
VALUES ('2020-02-07', '07:59:00', FALSE),
|
||||
('2020-02-10', '07:50:00', FALSE),
|
||||
('2020-02-11', '08:01:00', FALSE),
|
||||
('2020-02-12', '08:14:00', FALSE),
|
||||
('2020-02-13', '08:12:00', FALSE),
|
||||
('2020-02-14', '07:51:00', FALSE),
|
||||
('2020-02-17', '07:59:00', FALSE),
|
||||
('2020-02-18', '08:05:00', FALSE),
|
||||
('2020-02-19', '07:34:00', FALSE),
|
||||
('2020-02-20', '07:33:00', FALSE),
|
||||
('2020-02-21', '07:56:00', FALSE),
|
||||
('2020-02-24', '08:02:00', FALSE),
|
||||
('2020-02-25', '08:13:00', FALSE),
|
||||
('2020-02-26', '08:42:00', FALSE),
|
||||
('2020-02-27', '07:49:00', TRUE),
|
||||
('2020-02-28', '08:16:00', FALSE),
|
||||
('2020-03-02', '08:22:00', FALSE),
|
||||
('2020-03-03', '08:20:00', FALSE),
|
||||
('2020-03-04', '08:12:00', FALSE),
|
||||
('2020-03-05', '08:32:00', FALSE),
|
||||
('2020-03-06', '04:41:00', FALSE),
|
||||
('2020-03-09', '07:05:00', FALSE),
|
||||
('2020-03-10', '07:34:00', FALSE),
|
||||
('2020-03-11', '07:39:00', TRUE),
|
||||
('2020-03-12', '07:50:00', FALSE),
|
||||
('2020-03-13', '08:26:00', FALSE),
|
||||
('2020-03-16', '07:51:00', FALSE),
|
||||
('2020-03-17', '07:50:00', FALSE),
|
||||
('2020-03-18', '07:19:00', FALSE),
|
||||
('2020-03-19', '07:55:00', FALSE),
|
||||
('2020-03-20', '05:43:00', TRUE),
|
||||
('2020-03-23', '08:05:00', FALSE),
|
||||
('2020-03-24', '08:21:00', FALSE),
|
||||
('2020-03-25', '08:10:00', FALSE),
|
||||
('2020-03-26', '10:31:00', FALSE),
|
||||
('2020-03-27', '04:55:00', FALSE),
|
||||
('2020-03-30', '08:21:00', FALSE),
|
||||
('2020-03-31', '08:01:00', FALSE)
|
||||
;
|
||||
@@ -4,42 +4,46 @@ create table public."Arbeitszeiten"
|
||||
(
|
||||
"Datum" date not null,
|
||||
"Arbeitszeit" interval(6) null,
|
||||
"HomeOffice" boolean default FALSE not null,
|
||||
constraint "Arbeitszeiten_pkey" primary key ("Datum")
|
||||
);
|
||||
|
||||
|
||||
-- # Definition der Ansichten
|
||||
-- ## Wöchentlich
|
||||
create view "Arbeitszeiten - Woche" ("Woche", "Gesamtarbeitszeit", "Arbeitstage", "Überstunden") as
|
||||
select
|
||||
to_char(date_trunc('week'::text, "Arbeitszeiten"."Datum"::timestamp with time zone),
|
||||
create view "Arbeitszeiten - Woche" ("Woche", "Gesamtarbeitszeit", "Arbeitstage", "Überstunden", "Home-Office-Tage") as
|
||||
select to_char(date_trunc('week'::text, "Arbeitszeiten"."Datum"::timestamp with time zone),
|
||||
'TMYYYY#WW'::text) as "Woche",
|
||||
sum("Arbeitszeiten"."Arbeitszeit") as "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum") as "Arbeitstage",
|
||||
sum("Arbeitszeiten"."Arbeitszeit") - count("Arbeitszeiten"."Datum") ::double precision * '08:00:00'::interval as "Überstunden"
|
||||
sum("Arbeitszeiten"."Arbeitszeit")::interval AS "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum")::bigint AS "Arbeitstage",
|
||||
(sum("Arbeitszeiten"."Arbeitszeit") -
|
||||
((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden",
|
||||
(count(*) filter (where "Arbeitszeiten"."HomeOffice"))::int as "Home-Office-Tage"
|
||||
from "Arbeitszeiten"
|
||||
group by (date_trunc('week'::text, "Arbeitszeiten"."Datum"::timestamp with time zone))
|
||||
order by (date_trunc('week'::text, "Arbeitszeiten"."Datum"::timestamp with time zone));
|
||||
|
||||
-- ## Monatlich
|
||||
create view "Arbeitszeiten - Monat" ("Monat", "Gesamtarbeitszeit", "Arbeitstage", "Überstunden") as
|
||||
select
|
||||
to_char(date_trunc('month'::text, "Arbeitszeiten"."Datum"::timestamp with time zone),
|
||||
create view "Arbeitszeiten - Monat" ("Monat", "Gesamtarbeitszeit", "Arbeitstage", "Überstunden", "Home-Office-Tage") as
|
||||
select to_char(date_trunc('month'::text, "Arbeitszeiten"."Datum"::timestamp with time zone),
|
||||
'TMYYYY TMMonth'::text) as "Monat",
|
||||
sum("Arbeitszeiten"."Arbeitszeit") as "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum") as "Arbeitstage",
|
||||
sum("Arbeitszeiten"."Arbeitszeit") - count("Arbeitszeiten"."Datum") ::double precision * '08:00:00'::interval as "Überstunden"
|
||||
sum("Arbeitszeiten"."Arbeitszeit")::interval AS "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum")::bigint AS "Arbeitstage",
|
||||
(sum("Arbeitszeiten"."Arbeitszeit") -
|
||||
((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden",
|
||||
(count(*) filter (where "Arbeitszeiten"."HomeOffice"))::int as "Home-Office-Tage"
|
||||
from "Arbeitszeiten"
|
||||
group by (date_trunc('month'::text, "Arbeitszeiten"."Datum"::timestamp with time zone))
|
||||
order by (date_trunc('month'::text, "Arbeitszeiten"."Datum"::timestamp with time zone));
|
||||
|
||||
-- ## Jährlich
|
||||
create view "Arbeitszeiten - Jahr"("Jahr", "Gesamtarbeitszeit", "Arbeitstage", "Überstunden") as
|
||||
select
|
||||
date_part('year'::text, "Arbeitszeiten"."Datum")::text as "Jahr",
|
||||
sum("Arbeitszeiten"."Arbeitszeit") as "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum") as "Arbeitstage",
|
||||
sum("Arbeitszeiten"."Arbeitszeit") - count("Arbeitszeiten"."Datum") ::double precision * '08:00:00'::interval as "Überstunden"
|
||||
create view "Arbeitszeiten - Jahr"("Jahr", "Gesamtarbeitszeit", "Arbeitstage", "Überstunden", "Home-Office-Tage") as
|
||||
select date_part('year'::text, "Arbeitszeiten"."Datum")::text as "Jahr",
|
||||
sum("Arbeitszeiten"."Arbeitszeit")::interval AS "Gesamtarbeitszeit",
|
||||
count("Arbeitszeiten"."Datum")::bigint AS "Arbeitstage",
|
||||
(sum("Arbeitszeiten"."Arbeitszeit") -
|
||||
((count("Arbeitszeiten"."Datum"))::double precision * '08:00:00'::interval)) AS "Überstunden",
|
||||
(count(*) filter (where "Arbeitszeiten"."HomeOffice"))::int as "Home-Office-Tage"
|
||||
from "Arbeitszeiten"
|
||||
group by (date_part('year'::text, "Arbeitszeiten"."Datum"))
|
||||
order by (date_part('year'::text, "Arbeitszeiten"."Datum"));
|
||||
Reference in New Issue
Block a user