按时间取天和月的数据,和字符串截取函数

--取本月的数据,但是今天数据除外
     SELECT   *
     FROM  coustomertable
     WHERE  TO_CHAR (sb_date, 'mm') = TO_CHAR (SYSDATE, 'mm')
             AND sb_date <> TRUNC (SYSDATE)
     ORDER BY   sb_date DESC;
--去每月的汇总数据,除去本月的数据
     SELECT   SUM (SENT_QUANTITY) SENT_QUANTITY, TO_CHAR (SB_DATE, 'yyyy-mm')
     FROM   coustomertable
     WHERE   TO_CHAR (sb_date, 'mm') <> TO_CHAR (SYSDATE, 'mm')
     GROUP BY   TO_CHAR (SB_DATE, 'yyyy-mm')
     ORDER BY   TO_CHAR (SB_DATE, 'yyyy-mm') DESC;

--字符串的截取函数
select substr('12345',1,2) from dual
结果是12
select substr('12345',-2,2) from dual
结果是45
--day想取过去n天的数据
 where "MYONSTAR_REGISTER"."REGISTER_DATE" BETWEEN TO_DATE ( TO_CHAR ( SYSDATE -

30, 'mm-dd-yyyy' ) || '00:00:01', 'mm-dd-yyyy hh24:mi:ss' )
 AND TO_DATE ( TO_CHAR ( SYSDATE - 1, 'mm-dd-yyyy' ) || '23:59:59', 'mm-dd-yyyy

hh24:mi:ss' )

--month时间的格式是字符串的取月汇总的数据,出本月以外的。
 where substr("MYONSTAR_REGISTER_MONTH"."REGISTER_DATE", 6,2) <> substr(to_char

(SYSDATE,'yyyy/mm/dd'), 6,2)
     and substr("MYONSTAR_REGISTER_MONTH"."REGISTER_DATE", 1,4) = substr

(to_char(SYSDATE,'yyyy/mm/dd'), 1,4)

posted @ 2011-08-31 12:52  八神吻你  阅读(1003)  评论(0编辑  收藏  举报