mysql - 分别过去四个月的 Sum(count()) ?

标签 mysql sql

我必须分别找出过去 4 个月的总(计数)值和月份,我该如何做到这一点

表结构为

CREATE TABLE `lime_survey_16579` ( 
`id` int(11) NOT NULL auto_increment, 
`submitdate` datetime default NULL, 
`lastpage` int(11) default NULL, 
`startlanguage` varchar(20) collate utf8_unicode_ci NOT NULL, 
`token` varchar(36) collate utf8_unicode_ci default NULL, 
`16579X10X31` varchar(5) collate utf8_unicode_ci default NULLPRIMARY KEY (`id`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=480 ; 

此处 $survey = Lime_survey_16579 和 $temp= 16579X10X31 这里 16579X10X31 的值类似于 A1 A2 A3 ..

我如何才能给出类似的输出

tot month 

2 july 
4 aug 
6 sep 
9 oct 

有人可以帮我吗?

最佳答案

请尝试以下所有数据:

SELECT count(id) as tot, MONTHNAME(submitdate) as `month`
FROM lime_survey_16579
GROUP BY month(submitdate) 
ORDER BY month(submitdate)

要将数据限制为最近 4 个月,请尝试以下操作:

SELECT count(id) as tot, MONTHNAME(submitdate) as `month`
FROM lime_survey_16579
GROUP BY month(submitdate) 
ORDER BY month(submitdate) DESC
LIMIT 4

关于mysql - 分别过去四个月的 Sum(count()) ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13004638/

相关文章:

mysql - 从本地主机导出 drupal 站点导致丢失表

mysql - 在选择中选择值

php - 当 mysql 到远程服务器时,LOAD DATA LOCAL INFILE 不起作用

Sql server 从另一个表更新多列

php - MySQL - 记录最远的行程

sql - 在使用数组作为参数的函数中传递超过 100 个参数

mysql.connector.errors.InterfaceError : 2026 (HY000)

php - 正向前瞻正则表达式令人困惑

sql - 计算数组 SQL 中的 json 出现次数

c# - 我可以在位于 FTP 服务器上的数据库上远程运行 ACCESS 查询吗?