Queer European MD passionate about IT

data_and_schema.sql 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. BEGIN TRANSACTION;
  2. CREATE TABLE IF NOT EXISTS "Acquisti" (
  3. "IdFattura" INTEGER NOT NULL,
  4. "IdIngrediente" INTEGER NOT NULL,
  5. "Quantità" INTEGER NOT NULL,
  6. PRIMARY KEY("IdFattura","IdIngrediente")
  7. );
  8. CREATE TABLE IF NOT EXISTS "Birraie" (
  9. "IdPersona" INTEGER NOT NULL,
  10. "Soprannome" TEXT NOT NULL UNIQUE,
  11. PRIMARY KEY("IdPersona")
  12. );
  13. CREATE TABLE IF NOT EXISTS "Birrifici" (
  14. "IdBirrificio" INTEGER PRIMARY KEY AUTOINCREMENT,
  15. "Nome" TEXT,
  16. "AnnoFondazione" INTEGER,
  17. "Motto" TEXT,
  18. "Stemma" BLOB,
  19. "CapacitàProduttiva" INTEGER NOT NULL
  20. );
  21. CREATE TABLE IF NOT EXISTS "BirrificiBirraie" (
  22. "IdBirrificio" INTEGER NOT NULL,
  23. "IdBirraia" INTEGER NOT NULL,
  24. PRIMARY KEY("IdBirrificio","IdBirraia")
  25. );
  26. CREATE TABLE IF NOT EXISTS "Clienti" (
  27. "IdPersona" INTEGER NOT NULL,
  28. "IndirizzoSpedizione" TEXT NOT NULL,
  29. PRIMARY KEY("IdPersona")
  30. );
  31. CREATE TABLE IF NOT EXISTS "Fatture" (
  32. "IdFattura" INTEGER PRIMARY KEY AUTOINCREMENT,
  33. "IdBirrificio" INTEGER NOT NULL,
  34. "IdFornitore" INTEGER NOT NULL,
  35. "Data" TEXT NOT NULL,
  36. "NumeroFattura" INTEGER NOT NULL UNIQUE,
  37. "Importo" INTEGER NOT NULL
  38. );
  39. CREATE TABLE IF NOT EXISTS "Fornitori" (
  40. "IdFornitore" INTEGER PRIMARY KEY AUTOINCREMENT,
  41. "RagioneSociale" TEXT NOT NULL UNIQUE,
  42. "PartitaIva" INTEGER NOT NULL UNIQUE,
  43. "Indirizzo" TEXT NOT NULL
  44. );
  45. CREATE TABLE IF NOT EXISTS "Ingredienti" (
  46. "IdIngrediente" INTEGER PRIMARY KEY AUTOINCREMENT,
  47. "IdTipo" INTEGER NOT NULL,
  48. "Descrizione" TEXT NOT NULL
  49. );
  50. CREATE TABLE IF NOT EXISTS "IngredientiRicette" (
  51. "IdRicetta" INTEGER NOT NULL,
  52. "IdIngrediente" INTEGER NOT NULL,
  53. "Quantità" INTEGER NOT NULL,
  54. PRIMARY KEY("IdRicetta","IdIngrediente")
  55. );
  56. CREATE TABLE IF NOT EXISTS "Note" (
  57. "IdNota" INTEGER PRIMARY KEY AUTOINCREMENT,
  58. "IdProduzione" INTEGER NOT NULL,
  59. "Testo" TEXT NOT NULL
  60. );
  61. CREATE TABLE IF NOT EXISTS "NoteDegustazione" (
  62. "IdNota" INTEGER NOT NULL,
  63. "Giudizio" INTEGER NOT NULL,
  64. PRIMARY KEY("IdNota")
  65. );
  66. CREATE TABLE IF NOT EXISTS "Persone" (
  67. "IdPersona" INTEGER PRIMARY KEY AUTOINCREMENT,
  68. "Nome" TEXT NOT NULL,
  69. "Cognome" TEXT NOT NULL,
  70. "Email" TEXT NOT NULL,
  71. "CodiceFiscale" TEXT NOT NULL UNIQUE
  72. );
  73. CREATE TABLE IF NOT EXISTS "Prenotazioni" (
  74. "IdCliente" INTEGER NOT NULL,
  75. "IdProduzione" INTEGER NOT NULL,
  76. "Stato" INTEGER,
  77. "Quantità" INTEGER NOT NULL,
  78. PRIMARY KEY("IdProduzione","IdCliente")
  79. );
  80. CREATE TABLE IF NOT EXISTS "Produzioni" (
  81. "IdProduzione" INTEGER PRIMARY KEY AUTOINCREMENT,
  82. "IdRicetta" INTEGER NOT NULL,
  83. "DataProduzione" TEXT NOT NULL,
  84. "NumeroLotto" INTEGER NOT NULL,
  85. "Stato" INTEGER,
  86. "NumeroBottiglie" INTEGER NOT NULL
  87. );
  88. CREATE TABLE IF NOT EXISTS "Ricette" (
  89. "IdRicetta" INTEGER PRIMARY KEY AUTOINCREMENT,
  90. "IdBirrificio" INTEGER NOT NULL,
  91. "IdCreatrice" INTEGER NOT NULL,
  92. "IdRicettaMadre" INTEGER,
  93. "Nome" TEXT NOT NULL,
  94. "DataCreazione" TEXT NOT NULL,
  95. "Stato" INTEGER
  96. );
  97. CREATE TABLE IF NOT EXISTS "TipiIngredienti" (
  98. "IdTipo" INTEGER PRIMARY KEY AUTOINCREMENT,
  99. "Tipo" TEXT NOT NULL,
  100. "UnitàDiMisura" TEXT NOT NULL
  101. );
  102. INSERT INTO "Fornitori" ("IdFornitore","RagioneSociale","PartitaIva","Indirizzo") VALUES (1,'Luppoli per tutti i gusti',121457,'Corso Torre 125'),
  103. (2,'A tutto Malto',147963,'Piazza Dante 16'),
  104. (3,'Lievitami',236541,'Corso Pavia 33');
  105. INSERT INTO "Fatture" ("IdFattura","IdBirrificio","IdFornitore","Data","NumeroFattura","Importo") VALUES (1,1,1,'2020-01-03',125,77),
  106. (2,1,2,'2020-03-12',116,40),
  107. (3,1,3,'2020-03-18',78,82),
  108. (4,1,3,'2020-04-02',96,60);
  109. INSERT INTO "Birrifici" ("IdBirrificio","Nome","AnnoFondazione","Motto","Stemma","CapacitàProduttiva") VALUES (1,'Pirati Rossi',2020,'Arrrr','/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxMTEhUTExMWFhUXGBgYGBcYFxkYGBUeGhoaGBcYFxcYHSggGB0lHRgXITEhJSktLi4uGB8zODMtNygtLisBCgoKDg0OFxAQGi0dHx0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLf/AABEIALgBEgMBIg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. INSERT INTO "BirrificiBirraie" ("IdBirrificio","IdBirraia") VALUES (3,1),
  111. (4,1);
  112. INSERT INTO "Birraie" ("IdPersona","Soprannome") VALUES (3,'MaVe'),
  113. (4,'GiuLe');
  114. INSERT INTO "Clienti" ("IdPersona","IndirizzoSpedizione") VALUES (1,'Via Ramazzini 14'),
  115. (2,'Corso Milano 2');
  116. INSERT INTO "Persone" ("IdPersona","Nome","Cognome","Email","CodiceFiscale") VALUES (1,'Antonio','Rossi','a.r@g.i','NNNNRRRR'),
  117. (2,'Enrico','Bianchi','e.b@g.c','EEEBBB'),
  118. (3,'Giovanni','Verdi','m.v@l.i','MV'),
  119. (4,'Giulia','Lelli','g.l@e.c','GL');
  120. INSERT INTO "Acquisti" ("IdFattura","IdIngrediente","Quantità") VALUES (1,1,12),
  121. (2,2,7);
  122. INSERT INTO "TipiIngredienti" ("IdTipo","Tipo","UnitàDiMisura") VALUES (1,'Luppolo','g / L (mash)'),
  123. (2,'Malto','g%'),
  124. (3,'Lievito','g%'),
  125. (4,'Zuccheri','g%'),
  126. (5,'Additivi','mg%');
  127. INSERT INTO "Ingredienti" ("IdIngrediente","IdTipo","Descrizione") VALUES (1,1,'Luppolo verde'),
  128. (2,1,'Amarillo');
  129. INSERT INTO "IngredientiRicette" ("IdRicetta","IdIngrediente","Quantità") VALUES (1,1,4);
  130. INSERT INTO "Ricette" ("IdRicetta","IdBirrificio","IdCreatrice","IdRicettaMadre","Nome","DataCreazione","Stato") VALUES (1,1,3,'','Bionda decisa','2020-01-01','');
  131. INSERT INTO "NoteDegustazione" ("IdNota","Giudizio") VALUES (1,7);
  132. INSERT INTO "Note" ("IdNota","IdProduzione","Testo") VALUES (1,1,'Troppo freddo ad aprile-maggio, meglio farla d''estate');
  133. INSERT INTO "Produzioni" ("IdProduzione","IdRicetta","DataProduzione","NumeroLotto","Stato","NumeroBottiglie") VALUES (1,1,'2020-05-01',12447,NULL,12),
  134. (2,1,'2020-04-15',12443,0,0);
  135. INSERT INTO "Prenotazioni" ("IdCliente","IdProduzione","Stato","Quantità") VALUES (1,1,'',4),
  136. (1,2,NULL,6);
  137. CREATE VIEW Query_a
  138. AS SELECT r.IdRicetta, r.Nome
  139. FROM Ricette r
  140. JOIN Persone p ON p.IdPersona = r.IdCreatrice
  141. WHERE p.Nome = 'Giovanni';
  142. CREATE VIEW Query_b
  143. AS SELECT fa.IdBirrificio,
  144. COUNT(DISTINCT fa.IdFornitore) DiversiFornitori
  145. FROM Fatture fa
  146. WHERE fa.Data >= '2020-01-01'
  147. GROUP BY fa.IdBirrificio
  148. HAVING COUNT(DISTINCT fa.IdFornitore) >= 3
  149. ORDER BY COUNT(DISTINCT fa.IdFornitore) DESC;
  150. CREATE VIEW Query_c
  151. AS SELECT fo.RagioneSociale, SUM(fa.Importo) ImportoTotale,
  152. AVG(fa.Importo) ImportoMedio
  153. FROM Fornitori fo
  154. JOIN Fatture fa ON fa.IdFornitore = fo.IdFornitore
  155. JOIN Birrifici b ON b.IdBirrificio = fa.IdBirrificio
  156. WHERE b.Nome = 'Pirati Rossi'
  157. GROUP BY fo.IdFornitore, fo.RagioneSociale
  158. HAVING SUM(fa.Importo) > 10;
  159. CREATE VIEW Query_d
  160. AS SELECT b.Soprannome
  161. FROM Birraie b
  162. WHERE EXISTS (SELECT *
  163. FROM Ricette r
  164. WHERE r.IdCreatrice = b.IdPersona);
  165. CREATE VIEW Query_e
  166. AS SELECT DISTINCT p1.IdPersona, p1.Nome, p1.Cognome
  167. FROM Persone p1
  168. JOIN Prenotazioni pre1
  169. ON pre1.IdCliente = p1.IdPersona
  170. JOIN Produzioni pro1
  171. ON pro1.IdProduzione = pre1.IdProduzione
  172. JOIN Ricette r1
  173. ON r1.IdRicetta = pro1.IdRicetta
  174. WHERE NOT EXISTS (SELECT *
  175. FROM Prenotazioni pre2
  176. JOIN Produzioni pro2
  177. ON pro2.IdProduzione = pre2.IdProduzione
  178. JOIN Ricette r2 ON r2.IdRicetta = pro2.IdRicetta
  179. WHERE pre2.IdCliente = pre1.IdCliente
  180. AND r2.IdBirrificio <> r1.IdBirrificio);
  181. CREATE VIEW Query_f
  182. AS SELECT r1.IdBirrificio, pro1.NumeroLotto
  183. FROM Produzioni pro1
  184. JOIN Ricette r1 ON r1.IdRicetta = pro1.IdRicetta
  185. WHERE pro1.NumeroLotto = (SELECT MAX(pro2.NumeroLotto)
  186. FROM Produzioni pro2
  187. JOIN Ricette r2
  188. ON r2.IdRicetta = pro2.IdRicetta
  189. WHERE r2.IdBirrificio = r1.IdBirrificio);
  190. CREATE VIEW IngredientiUsati (IdIngrediente, Ingrediente,
  191. Usati)
  192. AS SELECT i.IdIngrediente IdIngrediente, i.Descrizione Ingrediente,
  193. SUM(ir.Quantità) Usati
  194. FROM IngredientiRicette ir
  195. JOIN Ingredienti i ON i.IdIngrediente = ir.IdIngrediente
  196. JOIN Produzioni p ON p.IdRicetta = ir.IdRicetta
  197. WHERE p.Stato = 0
  198. GROUP BY i.IdIngrediente, i.Descrizione;
  199. CREATE VIEW IngredientiInUso (IdIngrediente, Ingrediente, InUso)
  200. AS SELECT i.IdIngrediente IdIngrediente, i.Descrizione Ingrediente,
  201. SUM(ir.Quantità) InUso
  202. FROM IngredientiRicette ir
  203. JOIN Ingredienti i ON i.IdIngrediente = ir.IdIngrediente
  204. JOIN Produzioni p ON p.IdRicetta = ir.IdRicetta
  205. WHERE p.Stato IS NULL
  206. GROUP BY i.IdIngrediente, i.Descrizione;
  207. CREATE VIEW IngredientiAcquistatiTotali (IdIngrediente, Ingrediente,
  208. Totale)
  209. AS SELECT i.IdIngrediente IdIngrediente, i.Descrizione Ingrediente,
  210. SUM(a.Quantità) Totale
  211. FROM Acquisti a
  212. JOIN Ingredienti i ON i.IdIngrediente = a.IdIngrediente
  213. GROUP BY i.IdIngrediente, i.Descrizione;
  214. CREATE VIEW Inventario (IdIngrediente, Ingrediente, QuantitàTotale,
  215. QuantitàDisponibile)
  216. AS SELECT iat.IdIngrediente IdIngrediente,
  217. iat.Ingrediente Ingrediente,
  218. (iat.Totale - COALESCE(iu.Usati, 0)) QuantitàTotale,
  219. (iat.Totale - COALESCE(iu.Usati, 0)
  220. - COALESCE(iiu.InUso, 0)) QuantitàDisponibile
  221. FROM IngredientiAcquistatiTotali iat
  222. LEFT JOIN IngredientiUsati iu
  223. ON iu.IdIngrediente = iat.IdIngrediente
  224. LEFT JOIN IngredientiInUso iiu
  225. ON iiu.IdIngrediente = iat.IdIngrediente
  226. WHERE iat.Totale - COALESCE(iu.Usati, 0) > 0;
  227. COMMIT;