Guest User

Untitled

a guest
Jan 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. create function korektaCenyNalisnika(idnalesnika int) returns void as
  2. $$
  3. declare
  4. float avg;
  5. begin
  6. create temp table times as select id_bazowego_nalesnika as id_nalesnika,count(*) as sztuk from kompozycje group by id_nalesnika;
  7.  
  8. select avg(sztuk) into avg from times;
  9.  
  10. update bazowe_nalesniki b
  11. set koszt = case
  12. when avg<sztuk then koszt*1.05
  13. else koszt *0.95 end
  14.  
  15. from times t
  16. where t.id_nalesnika = b.id_nalesnika and b.id_nalesnika=idnalesnika;
  17.  
  18. drop table times;
  19. end;
  20. $$
  21. language plpgsql;
Add Comment
Please, Sign In to add comment