Home >Database >Mysql Tutorial >按月份统计某一个机构的某列出现的次数

按月份统计某一个机构的某列出现的次数

WBOY
WBOYOriginal
2016-06-07 15:28:061379browse

设计一张表 a 结构是 user_id 用户id user_name 用户姓名 web_id 用户所属网站id createtime 用户创建时间 需求:统计各个网站id每个月新增的用户数量 select count(*),to_char(a.createtime,yyyy-mm),a.web_id from 表 a where a.createtime is not null gr

设计一张表 a 结构是

user_id 用户id

user_name 用户姓名

web_id 用户所属网站id

createtime 用户创建时间

需求:统计各个网站id每个月新增的用户数量

select count(*),to_char(a.createtime,'yyyy-mm'),a.web_id

from 表 a where a.createtime is not null

group by to_char(a.createtime,'yyyy-mm'), /*按创建时间来统计*/

a.web_id /*按网站来统计*/

order by a.web_id ,to_char(a.createtime,'yyyy-mm') desc ;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:undo管理Next article:Solaris11添加swap方法