在PHP mySql中按频率排序关键字 [英] order keywords by frequency in PHP mySql

查看:104
本文介绍了在PHP mySql中按频率排序关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含视频ID和每个视频N个关键字的数据库. 我制作了一张表格,每行有1个视频ID和1个关键字ID.

I've got a database with video ids and N keywords for each video. I made a table with 1 video ID and 1 keyword ID in each row.

按频率排序关键字最简单的方法是什么? 我的意思是提取使用关键字的次数并对其进行排序.

What's the easiest way to order keywords by frequency? I mean to extract the number of times a keyword is used and order them.

是否可以使用sql来做到这一点,或者我需要使用php数组吗?

Is it possible to do that with sql or do I need to use php arrays?

谢谢

推荐答案

我认为这里不需要加入.只需列出所有关键字以及该关键字出现的次数(从最频繁到不频繁)即可.

I don't see the need for a join here. Simply list all the keywords along with the number of times the keyword appears, ordered from most frequent to less frequent.

SELECT keyword, COUNT(*) freq 
FROM keywordTable 
GROUP BY keyword 
ORDER BY freq DESC

这篇关于在PHP mySql中按频率排序关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆