OXBOW | Prémiové krmivá

CREATE VIEW zamestnanci_naklady AS
SELECT CONCAT(z.meno, ' ', z.priezvisko) AS Zamestnanec, 
       MONTH(u.datum) AS Mesiac, 
       YEAR(u.datum) AS Rok, 
       SUM(u.suma) AS Suma
FROM uctovny_dennik u
JOIN zamestnanci z ON u.zamestnanec = z.id
GROUP BY CONCAT(z.meno, ' ', z.priezvisko), MONTH(u.datum), YEAR(u.datum);

 


 

SELECT z.meno + ' ' + z.priezvisko as Zamestnanec, MONTH(ud.datum) as Mesiac, YEAR(ud.datum) as Rok, SUM(CASE WHEN ud.strana = 'D' THEN ud.suma ELSE -ud.suma END) as Suma FROM uctovny_dennik ud JOIN zamestnanci z ON ud.zamestnanec = z.id GROUP BY z.meno, z.priezvisko, MONTH(ud.datum), YEAR(ud.datum) ORDER BY Suma DESC

 

CREATE VIEW zamestnanci_naklady_view
AS
SELECT 
    z.meno,
    z.priezvisko,
    MONTH(u.datum) AS mesiac,
    YEAR(u.datum) AS rok,
    SUM(CASE WHEN u.strana = 'D' THEN -u.suma ELSE u.suma END) AS suma
FROM uctovny_dennik u
JOIN zamestnanci z ON u.zamestnanec = z.id
GROUP BY z.meno, z.priezvisko, MONTH(u.datum), YEAR(u.datum)

 

 



CREATE VIEW naklady_zam AS 
SELECT z.Id, z.Meno, z.Priezvisko, MONTH(u.datum) AS mesiac, YEAR(u.datum) AS rok, SUM(u.suma) AS naklady
FROM zamestnanci z 
JOIN uctovny_dennik u ON z.Id = u.zamestnanec 
GROUP BY z.Id, z.Meno, z.Priezvisko, MONTH(u.datum), YEAR(u.datum)