开发者

help to creating a formula on mysql to create another column on another table

开发者 https://www.devze.com 2023-02-14 22:31 出处:网络
just starting with mysql... had this table rating with this placement... http://i.stack.imgur.开发者_JAVA技巧com/kExbh.jpg

just starting with mysql... had this table rating with this placement...

http://i.stack.imgur.开发者_JAVA技巧com/kExbh.jpg

i want to get the average value of rating on a specific question_id(example: question_id=1, therefore: (5+4+3)/3=average and question_id=2, therefore:(3+4)/2=average) and transfer the value of average to another table which is result...that would look like below...

http://i.stack.imgur.com/j1erd.jpg

any help will be greatly appreciated...^^


You can use this query:

INSERT INTO results (subject_id, question_id, average)
SELECT subject_id, question_id, AVG(rating)
FROM rating
GROUP BY subject_id, question_id
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号