gpt4 book ai didi

php - 如何显示 MySQL 数据库中的热门搜索词并按日期分组

转载 作者:行者123 更新时间:2023-11-30 22:16:23 24 4
gpt4 key购买 nike

我有一个 MySQL 数据库,看起来很像这样:

Term-----------LOB---------Date------dde            JM Part A   2016-07-01drug waste     JM Part A   2016-07-01drug waste     JM Part A   2016-07-01Duplicates     JM Part A   2016-07-01credit balance JM Part B   2016-07-01drug waste     JM Part B   2016-07-01

所以,我想要每个 LOB(lob 是一个类别)每月的前 4(或 n)个“条款”

所以在这个例子中它可以是

JM Part A July 2016--dde            - 7--drug waste     - 5--credit balance - 3--duplicates     - 1
JM Part B - July 2016--dde            - 7--discharge stats- 5--credit balances- 3--overpayment    - 1

唉,有点失落了。到目前为止我能做的最好的是

SELECT term, lob, COUNT(term) uid_countFROM qsGROUP BY lobORDER BY uid_count DESCLIMIT 5

这似乎显示了所有 lob 和所有日期范围的前 5 个搜索词。

因此,我们将不胜感激任何帮助。我正在查看在 PHP 页面上显示报告。

感谢您的宝贵时间。

最佳答案

如果不同 Lob 的数量很少..你可以使用 union

 (select Term, count(*) 
from my_tbale
where Lob = 'JM Part A'
group by Term, `Date`
order by count(*) desc limit 5)
union
(select Term, count(*)
from my_tbale
where Lob = 'JM Part B'
group by Term, `Date`
order by count(*) desc limit 5)

关于php - 如何显示 MySQL 数据库中的热门搜索词并按日期分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38152983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com