转载

oracle日期转换成星期

现在有个数据分析的工作,需要分析网站注册会员的一些情况:
1.工作日、工作时间注册的的会员成为付费会员的比列,
2.工作日、非工作时间注册的的会员成为付费会员的比列,
3,非工作日,非工作时间注册的的会员成为付费会员的比列。
4,非工作日,工作时间注册的的会员成为付费会员的比列
工作时间按:08:30到17:30
工作日:周一到周五。
查看工作日,工作时间的注册会员总数:
select count(*) from member_info1234 where to_char(register_date,'d')>1 and to_char(register_date,'d')<7 and to_char(register_date,'HH24:mi:ss')>'08:00:00' and to_char(register_date,'HH24:mi:ss')<'17:30:00';
注释:先通过to_char(sysdate,'d') 来把日期转换成星期的第几天,具体对照关系如下:
星期日----1
星期一----2
星期六----7
然后to_char(register_date,'d')>1 and to_char(register_date,'d')<7 这样就选择出来了工作日。
工作时间就是利用to_char(register_date,'HH24:mi:ss')>'08:00:00' and to_char(register_date,'HH24:mi:ss')<'17:30:00'选择出来的。
前面四个需求的具体实现如下:
1.查看工作日,工作时间注册的会员数
select count(1) from member_info1234 where to_char(register_date,'d')>1 and to_char(register_date,'d')<7
and to_char(register_date,'HH24:mi:ss')>'08:00:00' and to_char(register_date,'HH24:mi:ss')<'17:30:00';
2..查看工作日,非工作时间注册的会员数
select count(1) from member_info1234 where to_char(register_date,'d')>1 and to_char(register_date,'d')<7
and ((to_char(register_date,'HH24:mi:ss')<'08:00:00' and to_char(register_date,'HH24:mi:ss')>'00:00:00')
or (to_char(register_date,'HH24:mi:ss')<'23:59:59' and to_char(register_date,'HH24:mi:ss')>'17:30:00')) ;
3..查看非工作日,工作时间注册的会员数
select count(1) from member_info1234 where (to_char(register_date,'d')=1 or to_char(register_date,'d')=7)
and to_char(register_date,'HH24:mi:ss')>'08:00:00' and to_char(register_date,'HH24:mi:ss')<'17:30:00';
4..查看非工作日,非工作时间注册的会员数
select count(1) from member_info1234 where (to_char(register_date,'d')=1 or to_char(register_date,'d')=7)
and ((to_char(register_date,'HH24:mi:ss')<'08:00:00' and to_char(register_date,'HH24:mi:ss')>'00:00:00')
or (to_char(register_date,'HH24:mi:ss')<'23:59:59' and to_char(register_date,'HH24:mi:ss')>'17:30:00'));
我们从这些数据比例如下:
1.工作日、工作时间注册的的会员成为付费会员的比列, ----50605, 805 比列为0.015
2.工作日、非工作时间注册的的会员成为付费会员的比列,----12188 , 70 比列为0.0057
3,非工作日,工作时间注册的的会员成为付费会员的比列。----7316, 82 比列为0.011
4,非工作日,非工作时间注册的的会员成为付费会员的比列 ---2907 ,19 比列为0.0065
通过这些比例可以了解到在工作日和工作时间注册的会员价值最高,成为付费会员的可能性越大,并且可能是因为有的单位周六日也上班,导致非工作日,工作时间注册的的会员成为付费会员的比列是第二大的,总起来说就是在工作时间注册的会员,成为付费会员的可能性比较大,可以去告诉业务人员去重点去发展,
关于to_char的一些常用的用法 :
Select to_char(sysdate,'ss') from dual取当前时间秒部分
Select to_char(sysdate,'mi') from dual取当前时间分钟部分
Select to_char(sysdate,'HH24') from dual取当前时间秒小时部分
Select to_char(sysdate,'DD') from dual取当前时间日期部分
Select to_char(sysdate,'MM') from dual取当前时间月部分
Select to_char(sysdate,'YYYY') from dual取当前时间年部分
Select to_char(sysdate,'w') from dual取当前时间是一个月中的第几周(从1日开始算)
Select to_char(sysdate,'ww') from dual取当前时间是一年中的第几周(从1.1开始算)
Select to_char(sysdate,'iw') from dual取当前时间是一年中的第几周(按实际日历的)
Select to_char(sysdate,'d') from dual取当前时间是一周的第几天,从星期天开始,周六结束
Select to_char(sysdate,'day') from dual 取当前日是星期几,和数据库设置的字符集有关,会输出'Tuesday'
Select to_char(sysdate,'ddd') from dual 当前日是一年中的第几天



正文到此结束
Loading...