1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| CREATE TABLE [Commandes] (
[Commande_Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
[DateRec] DATE NOT NULL,
[HeureRec] TIME NOT NULL);
CREATE TABLE [Produits] (
[Ref_Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
[Titre] TEXT NULL,
[Description] TEXT NULL,
[TypeRef] TEXT NOT NULL,
[PrixUnite] NUMERIC NOT NULL);
CREATE TABLE [Est_Constitue_De] (
[Commande_Id] INTEGER NOT NULL references commandes(commande_id),
[Ref_Id] INTEGER NOT NULL references Produits(Ref_Id),
[Quantite] INTEGER NOT NULL,
PRIMARY KEY ([Commande_Id], [Ref_Id]));
CREATE VIEW [PrixParCommande] AS
select c.commande_id, c.daterec, c.heurerec,
sum(e.quantite * r.Prixunite) as Prix_Total
from commandes c
join est_constitue_de e on c.commande_id = e.commande_id
join Produits r on r.ref_id = e.ref_id
group by c.commande_id, c.daterec, c.heurerec; |
Partager