oracle日期如何转换成星期

33次阅读
没有评论

共计 2721 个字符,预计需要花费 7 分钟才能阅读完成。

这篇文章将为大家详细讲解有关 oracle 日期如何转换成星期,丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

现在有个数据分析的工作,需要分析网站注册会员的一些情况:

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 当前日是一年中的第几天

关于“oracle 日期如何转换成星期”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-19发表,共计2721字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)