Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. /*EX1*/
  2. DELIMITER //
  3. CREATE TRIGGER EXERCICI1INSERT AFTER INSERT ON NOTES FOR EACH ROW
  4.  
  5. BEGIN
  6. IF (select count(*) from notes_alumne where dni = new.dni)=0 then
  7.  
  8. IF ((select sum(nota) from notes where codi like 'E%'and dni=new.dni)*0.75) + ((select sum(nota) from notes where codi like 'P%' and dni=new.dni)*0.25) / (select count(*) from notes where dni=new.dni)>=5 then
  9.  
  10. INSERT INTO NOTES_ALUMNE VALUES (new.dni, (((select sum(nota) from notes where codi like 'E%' and dni=new.dni)*0.75) + ((select sum(nota) from notes where codi like 'P%' and dni=new.dni)*0.25)) / (select count(*) from notes where dni=new.dni), 'A');
  11.  
  12. else
  13.  
  14. INSERT INTO NOTES_ALUMNE VALUES (new.dni, (((select sum(nota) from notes where codi like 'E%' and dni=new.dni)*0.75) + ((select sum(nota) from notes where codi like 'P%' and dni=new.dni)*0.25) / (select count(*) from notes where dni=new.dni)), 'S');
  15.  
  16. end if;
  17. else
  18.  
  19. IF ((select sum(nota) from notes where codi like 'E%'and dni=new.dni)*0.75) + ((select sum(nota) from notes where codi like 'P%' and dni=new.dni)*0.25) / (select count(*) from notes where dni=new.dni)>=5 then
  20.  
  21. update notes_alumne set mitjana = (((select sum(nota) from notes where codi like 'E%'and dni=new.dni)*0.75) + ((select sum(nota) from notes where codi like 'P%' and dni=new.dni)*0.25) / (select count(*) from notes where dni=new.dni)) where dni=new.dni;
  22.  
  23. update notes_alumne set codi_nota = 'A' where dni=new.dni;
  24.  
  25. else
  26.  
  27. update notes_alumne set mitjana = (((select sum(nota) from notes where codi like 'E%'and dni=new.dni)*0.75) + ((select sum(nota) from notes where codi like 'P%' and dni=new.dni)*0.25) / (select count(*) from notes where dni=new.dni)) where dni=new.dni;
  28.  
  29. update notes_alumne set codi_nota = 'S' where dni=new.dni;
  30.  
  31. end if;
  32.  
  33. end if;
  34. END //
  35.  
  36. DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement