数据库计算日期,统计系统时间(月)的数据

2014-11-24 02:44:57 · 作者: · 浏览: 4

数据库计算日期,统计 系统时间(月)的数据
计算出本月第一天到最后一天的日期:
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)