MariaDb按月統計支出

2021-07-02 12:45:23 字數 1029 閱讀 1109



select date_format(create_time,'%y年%m月') months,sum(ccl.ccl_expense_money) 支出 from customer_cash_log ccl where ccl_customer_id=5 group by months;
關鍵函式:date_format

date_format(date,format)

根據format字串格式化date值。下列修飾符可以被用在format字串中:

%m 月名字(january……december)

%w 星期名字(sunday……saturday)

%d 有英語字首的月份的日期(1st, 2nd, 3rd, 等等。)

%y 年, 數字, 4 位

%y 年, 數字, 2 位

%a 縮寫的星期名字(sun……sat)

%d 月份中的天數, 數字(00……31)

%e 月份中的天數, 數字(0……31)

%m 月, 數字(01……12)

%c 月, 數字(1……12)

%b 縮寫的月份名字(jan……dec)

%j 一年中的天數(001……366)

%h 小時(00……23)

%k 小時(0……23)

%h 小時(01……12)

%i 小時(01……12)

%l 小時(1……12)

%i 分鐘, 數字(00……59)

%r 時間,12 小時(hh:mm:ss [ap]m)

%t 時間,24 小時(hh:mm:ss)

%s 秒(00……59)

%s 秒(00……59)

%p am或pm

%w 乙個星期中的天數(0=sunday ……6=saturday )

%u 星期(0……52), 這裡星期天是星期的第一天

%u 星期(0……52), 這裡星期一是星期的第一天

%% 乙個文字「%」。

按月份統計

id logtimes 12010 03 1213 04 412 2010 04 1313 04 443 2010 05 1813 04 444 2010 06 1813 04 445 2010 07 1813 04 446 2010 05 1813 04 447 2010 05 1813 04 4...

SQL按月統計

做統計就要和時間打交道。一 當前年的月統計 select b.number as month sum a.a4012 shouru,sum a.a4011 feiyong,sum a.a4012 a4011 lirun from a040a001 a right join select number...

統計 Oracle按月統計(詳細)

建立表 test cteate table test id number not null,modifiedtime date not null 按月統計 select to char t.modifiedtime,yyyy mm time,count count from test t 這裡可加查...