SET NAMES utf8mb4;
USE `mitusovs_d_trenesanas_eksamenam_1`;

DROP VIEW IF EXISTS `mitusovs_d_result_1`;
CREATE VIEW `mitusovs_d_result_1` AS
SELECT
    DAYOFWEEK(d.`datums`) AS `Diena`,
    d.`datums` AS `Datums`,
    d.`sakuma_laiks` AS `No`,
    dt.`nosaukums` AS `Darba tips`,
    v.`nosaukums` AS `Vieta`,
    d.`kludas_apraksts` AS `Kļūdas apraksts`,
    d.`beigu_datums` AS `Datums līdz`,
    d.`beigu_laiks` AS `Līdz`,
    d.`darba_veiceji_teksts` AS `Darba veicējs`,
    c.`darba_nr` AS `Darba nr`,
    c.`darba_veids` AS `Cenrāža darba veids`,
    c.`mervieniba` AS `Mērv.`
FROM `darbi` d
JOIN `darba_tipi` dt ON dt.`darba_tips_id` = d.`darba_tips_id`
JOIN `vietas` v ON v.`vieta_id` = d.`vieta_id`
LEFT JOIN `cenradis` c ON c.`cenradis_id` = d.`cenradis_id`
ORDER BY d.`avota_rindas_nr`;

SELECT * FROM `mitusovs_d_result_1`;
