所以这几乎就是表格(已经缩小了所需的列)
DATEREGIS :
10-AUG-95
02-MAY-01
12-NOV-98
09-OCT-99
12-NOV-98
2-NOV-00
12-AUG-01
我想要做的是创建一个查询以找到最繁忙的月份。
这就是我现在所拥有的,但是它有各种各样的错误,我可以;因为我的生活把这一点弄清楚了。
SELECT
dateregistered, count(dateregistered) as count
FROM
pet
HAVING
count = MAX(count)
GROUP BY
dateregistered;
请提供任何帮助。
编辑* DBMS是SQL * Plus
答案 0 :(得分:0)
试试这个
Select Month,max(count)
from
(
SELECT datepart(mm,dateregistered) Month, count(*) as count
FROM pet
Group by datepart(mm,dateregistered);
)t
group by Month
答案 1 :(得分:0)
您可以参考此link来了解更多mysql函数。
SELECT MONTHNAME(dateregistered), count(dateregistered) as count
FROM `pet`
group by MONTH(dateregistered)
order by MONTH(dateregistered) desc
答案 2 :(得分:0)
按月分组计数。按递减顺序排序并从此列表中选择第一行。
SELECT *
FROM
(
SELECT to_char(dateregistered,'mm') as month, count(*) as cnt
FROM pet
GROUP BY to_char(dateregistered,'mm')
ORDER BY count(*) DESC
)
WHERE ROWNUM = 1;