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

计算出本月第一天到最后一天的日期:

--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;

这个语句有点问题,月份是12月的时候,计算的年,没变化。 
 


计算出本月时间和下月时间的日期:

select  date(start_time) as startTime,date(start_time) +1 month as endTime from REPAYMENT
 

统计本月数据:

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)

猜你喜欢

转载自zhaining123129-gmail-com.iteye.com/blog/1717289
今日推荐