Answer the question
In order to leave comments, you need to log in
How to select the most frequently mentioned tags from a database using SQL?
Good afternoon!
I have a table in the Tags database that stores all tags (they are unique, that is, there are no two records in this table with the same tag)
There is a Posts table
There is a Posts_Tags table in which tags and posts are linked,
for example, there is a tag # car with id= 5
and in Post_Tags this tag is associated with posts with id=7 id=10 and so on
like this
posts tags
7 ---------5
10--------5
20----- ---5
I want to select all posts in the last hour where some tags were mentioned more than others.
Theoretically, I can select all the tags for the last hour from the database and then sort them in the code, but maybe there is an easier way? Can you please tell me how can I implement this?
Answer the question
In order to leave comments, you need to log in
select
top 100
tags,
COUNTposts
from
(
select tags, COUNT( posts ) as COUNTposts
from Posts_Tags
where (указываешь диапазон времени)
group by tags
) x
order by COUNTposts
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question