The sample time the top of the category and a certain number of the top titles for each section


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
10 views
Dear colleagues!
For several days I think on the request.
There is a table with the headings and table titles. Each of the headings and names there is a field rating.
Do the sample names with their headings.
The task is to select TOP 3 names from the TOP 3 categories. In other words I want to about the result was as follows:

movies | avatar | rating rubric 10 out of 100 names |
movies | the godfather | 10 rating rubric | rating names 90 |
films | star wars | rating rubric 10 out of 60 names |
TV shows | house MD | rubric rating of 8 out of 200 names |
series | SBM | 8 rating rubric | rating name 40 |
series | the interns | rating rubric 8 out names 10 |
cartoons | there once was a dog | rubric rating of 5 out of names 90 |
cartoons | Tom and Jerry | rubric rating of 5 out of names 80 |
cartoons | buruma dethroned | 5 rating rubric | rating names 66 |

In production, of course all of the entities more, but the essence is revealed.
Is there any beautiful solution?
by | 10 views

4 Answers

0 like 0 dislike
This is not your case habrahabr.ru/qa/437/?
by
0 like 0 dislike
As far as I understand you want to do it all in one query?
Please specify the names of the tables (can be suspended) and the main dependencies (i.e., if the rating is in another table, how the ID field, it determines its name).
by
0 like 0 dislike
It is desirable in one request. If it doesn't work nicely on MySQL, you will have to do several queries and store the results in cache, because a sample of one category would be about 30-120 milliseconds already.
Sample table structure:
Rating for table columns in the same table. And for the items a rating in the column of table names.
\r
items
— id
cat_id
title
rating
\r
cats
— id
title
rating
by
0 like 0 dislike
do a DESCRIBE `table name`;
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked May 22, 2019 by troodi
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
25,877 users