統計全年12個月資料

2021-09-02 05:37:36 字數 2311 閱讀 7179

查詢指定年份的count()值

這方法需要對沒有資料的月份進行處理

方法二:這方法需要定義乙個1-12月份的實體類,所有月份全部顯示,對應月份沒有資料的列置零

select coalesce(count(),0) as jan,

(select ifnull(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-02』)) as feb,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-03』)) as mar,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-04』)) as apr,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-05』)) as may,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-06』)) as jun,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-07』)) as jul,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-08』)) as aug,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-09』)) as sept,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-10』)) as octo,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-11』)) as nov,

(select coalesce(count(),0) froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-12』)) as dece

froms_orderas o

where date_format(o.ordertime,』%y-%m』) = concat(#,』-01』)

查詢結果為

統計商戶24個月連續流水總月數儲存過程

統計商戶24個月連續流水總月數儲存過程 刪除儲存過程 sql drop procedure checklen procedure dropped 建立儲存過程 sql create or replace procedure checklen val in varchar2,resultval out...

根據當月資料庫自動生成下個月資料庫 2

方法2.指令碼複製 use master goif exists select from dbo.sysobjects where id object id n dbo sp proccopydb and objectproperty id,n isprocedure 1 drop procedur...

根據當月資料庫自動生成下個月資料庫 2

方法2.指令碼複製 use master goif exists select from dbo.sysobjects where id object id n dbo sp proccopydb and objectproperty id,n isprocedure 1 drop procedur...