2025-09-01 07:56:13 +02:00
|
|
|
create view nb_total_familles as
|
|
|
|
|
select count(*) as nb_total_familles from famille;
|
|
|
|
|
|
|
|
|
|
create view nb_total_articles as
|
|
|
|
|
select count(*) as nb_total_articles from article;
|
|
|
|
|
|
|
|
|
|
create view nb_total_tickets as
|
|
|
|
|
select count(*) as nb_total_tickets from ticket;
|
|
|
|
|
|
|
|
|
|
create view nb_total_adherents as
|
|
|
|
|
select count(*) as nb_total_adherents from adherent;
|
2025-09-18 07:48:51 +02:00
|
|
|
|
|
|
|
|
create materialized view detail_ticket as
|
|
|
|
|
select t.id as ticket_id, t.date_ticket, t.mode_rglt,
|
|
|
|
|
h.id as adherent_id, h.codepostal, h.genre,
|
|
|
|
|
round(sum(l.total), 2) as total
|
|
|
|
|
from ticket t
|
|
|
|
|
join ligne l on l.ticket_id = t.id
|
|
|
|
|
join adherent h on h.id = t.adherent_id
|
|
|
|
|
group by t.id, h.id;
|
|
|
|
|
|
|
|
|
|
create materialized view detail_vente as
|
|
|
|
|
select t.id as ticket_id, t.date_ticket, t.mode_rglt,
|
|
|
|
|
h.id as adherent_id, h.codepostal, h.genre,
|
|
|
|
|
l.article_code, a.famille_code,
|
|
|
|
|
round(sum(l.total), 2) as total
|
|
|
|
|
from ticket t
|
|
|
|
|
join ligne l on l.ticket_id = t.id
|
|
|
|
|
join adherent h on h.id = t.adherent_id
|
|
|
|
|
join article a on a.code = l.article_code
|
|
|
|
|
group by t.id, h.id, l.article_code, a.famille_code;
|
2025-11-01 08:18:17 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
INSERT INTO prix_historique (article_code, prix_unitaire, dates)
|
|
|
|
|
SELECT
|
|
|
|
|
article_code,
|
|
|
|
|
prix_unitaire,
|
|
|
|
|
daterange(
|
|
|
|
|
date(MIN(t.date_ticket)),
|
|
|
|
|
date(LEAD(MIN(t.date_ticket)) OVER (PARTITION BY article_code ORDER BY MIN(t.date_ticket)))
|
|
|
|
|
) AS dates
|
|
|
|
|
FROM ligne l
|
|
|
|
|
JOIN ticket t ON t.id = l.ticket_id
|
|
|
|
|
GROUP BY article_code, prix_unitaire
|
|
|
|
|
ORDER BY article_code, MIN(t.date_ticket);
|
|
|
|
|
*/
|