简体   繁体   中英

MySql calculate average grade

I am using MySql and have 2 tables.

在此处输入图片说明

What I need is an average grade of all reviews of that organizations. My question is, should I make a trigger and a procedure to allways update average grade on insert or just calculate it when needed? I am going to need it multiple (5-10) times on each page.

A general rule of thumb: Premature optimization are the mother of all evil. Start with calculating the average whenever you need it. If that becomes too slow, you can start thinking about optimizations such as caching it or pre-calculating it and saving it to the database (eg, by a trigger, like you proposed).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM