Skip to content
Advertisement

Invaild use of group function

I am trying to make an after insert trigger that will add the bnumber to the table available with the rack-id that has the most open slots. To get this I need to take the total number of slots – the number of instances and if there are no free slots then the insert will fail. Below is what I have came up with so far but I don not know if it is at all correct and right now it throws 1111: Invalid use of Group function.

updated non error code but is not inserting anything into the table Available

Tables:

so in this examples when you add a new bike it will be something like bnumber 4. It will then get the count of instances of rack-id so 2 instances of rack-id 0 and 1 instance of rack-id 1. Then it will subtract the the instances from the corresponding num-holds. so this step would be rack-id 0 has 3 num-holds - 2 instances = 1 empty slot available. rack-id 1 has 4 num-holds - 1 instance = 3 empty slots, so bnumber 4 would be inserted into rack with the rack-id 1.

Advertisement

Answer

First, you are missing a ON clause:

it will look something like this:

Then, in your outer query:

You are missing a GROUP BY new.bnumber and also HAVING clause is use instead WHERE when you need to filter by aggregation.


User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement