I have a problem that I cannot solve, I was asked to implement facebook type "likes" in a blog, and I programmed it and I am getting:
But now they want the blog article to be more or less reliable, depending on the valuation, in the database I did the following:
And, depending on the number of likes , I pigeonhole the article into a level and at the moment I have this:
SELECT * FROM wp_level;
SELECT SUM(`like`) AS result FROM wp_like WHERE id_post = 22;
But if I apply a JOIN , it only returns the values that are equal and I don't know how to place if it is greater than and less than.
From already thank you very much!
It would be much better to redesign
wp_level
so that each row indicates a from/to range, to uniquely identify the confidence value, but also what you can do with what you already have is to filter the values of likes greater than or equal to, order by this amount in a way descending, and stay with the first row:In MySQL:
Although I like Patricio's proposal much better, I propose this alternative, in case you don't have the possibility to modify the tables as he indicates:
You can replace the
GROUP BY 1
byWHERE id_post=23
to categorize a single post.The values
NULL
are the limits of the extreme intervals.I pass you the dataset in SQL to do the tests:
Leave me any questions in the comments.
Hello, good evening, I just read your comments, yesterday I stayed up late and solved it this way (ugly) anyway, now seeing your answers I'm going to redo it in a better way.
Your answers seem more verbose to me, thank you very much!
Finally, I leave the structure that is the same as the one that David made except that I add one more table (wp_post_level) so that the level is processed and the number of likes is accumulated with a SUM (wp_post_level.likes), which does not have to be constantly doing the count instead they take the value of this field and in another (wp_post_level.id_level) I put the level id which acts as a foreign key.