Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
My code is:
$vote = DB::SELECT(DB::RAW("SELECT * FROM votes WHERE product_id = product_id; "));
Here[1] is a screenshot of my DB.
I'd like to ask how to select the same Producut Id in the SQL Query?
[1] https://i.sstatic.net/z1Jvc.png
SELECT * FROM votes WHERE product_id = 5
Producut Id
SELECT SUM(vote) FROM votes WHERE product_id = 5
If you want to count sum of votes for each product and sort sum of votes from highest to lowest, then your query is:
SELECT product_id, SUM(vote) as `vote_rate` FROM votes GROUP BY product_id ORDER BY `vote_rate` DESC
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
SELECT * FROM votes WHERE product_id = 5?Producut Idthe same as what???SELECT SUM(vote) FROM votes WHERE product_id = 5