需要编写一个存储过程来从sql配置单元中yymmddhhmmss类型的时间戳中提取小时数

drnojrws  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(412)

需要使用存储过程提取特定时间段内客户的呼叫号码。包含日期时间的列的格式为yymmddhhmmss。

20181202112658
20181201102326

当它是一个日期格式(11/09/2018 8:19:57)时,我使用下面的方法来完成上述操作,并获取特定时间内的通话次数。
选择主叫号码,

COUNT(CASE WHEN TO_CHAR(CALL_START_TIME,'HH24') BETWEEN '06' AND '08' THEN CALLING_NUMBER END) AS CDR6_9_COUNT,
SUM(CASE WHEN TO_CHAR(CALL_START_TIME,'HH24') BETWEEN '06' AND '08' THEN CALL_DURATION END) AS CDR6_9_DURATION,
hiz5n14c

hiz5n14c1#

只是使用 substr() :

SELECT CALLING_NUMBER,
       SUM(CASE WHEN SUBSTR(CALL_START_TIME, 9, 2) BETWEEN '06' and '08' THEN 1 ELSE 0 END) as CDR6_9_COUNT,
       . . .

如有必要,可能需要先将值转换为字符串:

SELECT CALLING_NUMBER,
       SUM(CASE WHEN SUBSTR(CAST(CALL_START_TIME AS string), 9, 2) BETWEEN '06' and '08' THEN 1 ELSE 0 END) as CDR6_9_COUNT,
       . . .

相关问题