I hope you’re doing good!
I’m taking the SQL for Data Analysis course and I’m having trouble with the Trigger creation part.
The Task2 required to create a function that returns a trigger. Here is my code below:
create function avg_qty() returns trigger as $avg_amount$ declare avg_amount integer; begin select avg(qty) into avg_amount from order_info; insert into avg_qty_log(order_id, avg_qty) values (new.order_id, avg(qty)); return new; end; $avg_amount$ language plpgsql;
I tried to insert the average of the sales amount into the table avg_amount that we created in the Task1. And then, I inserted to new values we just added, with the identifiable and the average.
The query is not right according to the Task.
Can someone give me a clue?
Thanks by advance!