數據庫計算日期,統計系統時間(月)的數據
計算出本月第一天到最後一天的日期:
www.2cto.com
select date(rtrim(char(year(min(start_time))))||'-'||rtrim(char(month(min(start_time))))||'-1') as startTime,
date(rtrim(char(year(max(start_time))))||'-'||rtrim(char(month(max(start_time)+1 month)))||'-1') as endTime from table_A t;
統計本月數據:
select sum(MONTHLY_REPAYMENTS) as totle from TABLE_A where ID='123'
AND date('2012-11-01') < date(current timestamp ) and date('2012-12-01') > date(current timestamp)