php - How I can order mysql with rate to every column
Get the solution ↓↓↓I have a table named "Articles" and wants to show in order with rating to every column for example in this table there are 2 column with names "Likes" and "Views" I want "Likes" Multiplied by X2 and "Views" Multiplied by X1 so If an article has 14 likes and 15 views rating for this article will be :
14 X 2 = 28
15 X 1 = 15
Total : 43
I want show all articles by total order :) Regards
Answer
Solution:
You can try like this
select * , (Likes * 2 + Views * 1) as count from tablename order by count ASC
Answer
Solution:
Gather the computation in an extra column and order by this column like:
SELECT *, ((views)*1 + (likes)*2) AS total_count FROM Articles
ORDER BY total_count DESC
but this will not be fast, since you cannot put an index on this column... think about using a cache column, on which you can put an index.
Answer
Solution:
Use the ORDER BY clause to compute the rating, like this:
SELECT *
FROM Articles
ORDER BY likes*2+views DESC
Working Fiddle: http://sqlfiddle.com/#!2/927491/1
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: can't write image data to path
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.