sql - Average Number on entries where ID is the same as another table -


i have database making microsoft access 2013, there 2 tables. first table has productid primary key, second table has unique reviewid productid of product review referring to. in first table products information kept, want have field averages ratings given in it's reviews (kept in second table).

how average it's rating without averaging rating reviews, , reviews specific product?

based on descriptions i've created table called tblproducts following data:

enter image description here

i've created table called tblreview following data (here i've assumed have field store value each review's rating i've called reviewrating.. , i've assumed reviews rated 0-10):

enter image description here

i created query:

select tblproducts.productname, avg(tblreview.reviewrating) avgofreviewrating tblreview inner join tblproducts on tblreview.productid = tblproducts.productid group tblproducts.productname; 

...which results in:

enter image description here

note select query, won't put average review rating in original tblproducts table, need update query. wouldn't recommend though you'll have remember run update before using tblproducts needs up-to-date averages.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -