在sql中获取月度报告

时间:2012-11-15 11:14:28

标签: sql

我输入了我的数据库列日志,数据,类型 如何从一年后开始获取日志与月份区别 柔性: 行

logs = 'error...'
data = 2012-11-05 11:24:08
type = 1

.... 我希望在那个视图中得到它们

month     logs-count   type
January     100         1
January     100         2
February    160         1
February    120         2
 ....

3 个答案:

答案 0 :(得分:0)

试试这个,如果这些列在同一个表中

select monthname(data) as month,count(logs)as logs-count,type from table
 group by month

答案 1 :(得分:0)

试试这个:

select datename(month, data) as month count(logs)as logscount, type from table

答案 2 :(得分:0)

对于mysql:

select monthname(data) as month, count(*) as logs-count, type
  from table
  group by month, type

您需要按日期和类型进行分组,以便每月获得多行。