Solved Help with SQL query
-
@thegillion said in Help with SQL query:
@scottalanmiller I know you can user AVG like this
SELECT AVG(`Rating`) FROM `Reviews` WHERE `bathroom_ID` = 100
Yes, that I know works, too.
-
Is this an intentional fast lookup cache table? Because this violated the database integrity. Just a thought while I'm looking for an answer.
-
@thegillion said in Help with SQL query:
Maybe I'm obtuse, but why is there an AS Rating? Just remove that bit.
-
UPDATE bathrooms SET bathrooms.Rating = (SELECT AVG(Reviews.Rating) FROM Reviews WHERE Reviews.bathroom_ID = bathrooms.id)
-
Did that work?
-
@scottalanmiller said in Help with SQL query:
@thegillion said in Help with SQL query:
Maybe I'm obtuse, but why is there an AS Rating? Just remove that bit.
I was just looking at that and couldn't see where it was being used either.
-
@scottalanmiller said in Help with SQL query:
UPDATE bathrooms SET bathrooms.Rating = (SELECT AVG(Reviews.Rating) FROM Reviews WHERE Reviews.bathroom_ID = bathrooms.id)
@scottalanmiller said in Help with SQL query:
Did that work?
Yes it did work thank you!!!
-
@scottalanmiller said in Help with SQL query:
Is this an intentional fast lookup cache table? Because this violated the database integrity. Just a thought while I'm looking for an answer.
The bathroom table is the main table for lookups so yes and the server runs on SSDs with 4gb of ram and two 3.2ghz vCores
-
@thegillion said in Help with SQL query:
@scottalanmiller said in Help with SQL query:
UPDATE bathrooms SET bathrooms.Rating = (SELECT AVG(Reviews.Rating) FROM Reviews WHERE Reviews.bathroom_ID = bathrooms.id)
@scottalanmiller said in Help with SQL query:
Did that work?
Yes it did work thank you!!!
Boom, sweet! You can use the ellipses on the individual post to make it as the correct answer, too
-
@thegillion said in Help with SQL query:
@scottalanmiller said in Help with SQL query:
Is this an intentional fast lookup cache table? Because this violated the database integrity. Just a thought while I'm looking for an answer.
The bathroom table is the main table for lookups so yes and the server runs on SSDs with 4gb of ram and two 3.2ghz vCores
Are you going to do a scheduled batch run on this (tee hee, batch run) like at night to update the reviews?
-
@scottalanmiller said in Help with SQL query:
Are you going to do a scheduled batch run on this (tee hee, batch run) like at night to update the reviews?
I was going to do that or pass the ID of the bathroom then fire it on a review or bathroom submission.
-
@thegillion said in Help with SQL query:
@scottalanmiller said in Help with SQL query:
Are you going to do a scheduled batch run on this (tee hee, batch run) like at night to update the reviews?
I was going to do that or pass the ID of the bathroom then fire it on a review or bathroom submission.
You could use a database trigger for that, too.
-
If you expect this product to explode you might want to consider a NoSQL database now. Easy to switch now, hard later. MySQL scales pretty big, but things like MongoDB and Cassandra go so much bigger. Worth thinking about now before you are more or less locked in.
-
@scottalanmiller said in Help with SQL query:
If you expect this product to explode
Possible poor choice of words.
-
@BRRABill said in Help with SQL query:
@scottalanmiller said in Help with SQL query:
If you expect this product to explode
Possible poor choice of words.
Or... intentional.
-
@scottalanmiller said in Help with SQL query:
@BRRABill said in Help with SQL query:
@scottalanmiller said in Help with SQL query:
If you expect this product to explode
Possible poor choice of words.
Or... intentional.
Knowing you, intentional.