我正在使用此查询:
select substr("Message_Time",6,2) || '/' || substr("Message_Time",4,2) || '/' || '20'|| substr("Message_Time",2,2) || substr("Message_Time",8,2) || ':' || substr("Message_Time",10,2) as "Date",
count(*) as "Fault", "Message_Location", "Service_Name_U", "Operation_Name_U", "Port_Namespace_U",
"Error_Code_U", "Error_SubCode_U", "Fault_Code_U", "Fault_String_U",
"Requester_Identity", "Application_ServerName_U"
from "Fault_Log_Table_610"
where "Message_Time" >= 1181016220000000 and "Message_Time" < 1181017220000000 and
"Operation_Name_U" = 'getDomandeDisabile'
group by substr("Message_Time", 6, 2) || '/' || substr("Message_Time", 4, 2) || '/' || '20'|| substr("Message_Time", 2, 2) || substr("Message_Time",8,2) || ':' || substr("Message_Time",10,2),
"Service_Name_U", "Operation_Name_U", "Error_Code_U", "Error_SubCode_U", "Message_Location", "Fault_Code_U", "Fault_String_U",
"Port_Namespace_U", "Requester_Identity", "Application_ServerName_U"
我需要在“日期”字段中添加2小时,换句话说,我需要在substr(“ Message_Time”,8,2)中添加数字2。
日期的格式为1181020164532000,其中:
第一个数字是世纪 接下来的两个数字是年份 然后是两个数字 然后是两个数字 然后是两个数字 然后两个数字是分钟 最后三个数字是毫秒
答案 0 :(得分:1)
我将预先计算时间戳解析,然后将2小时添加到CTE(公用表表达式)中。
然后,我将在您想要的查询中使用这些现成的数据。像这样:
with x as (
select
timestampadd(8, 2, -- add 2 hours
timestamp_format( -- parse the VARCHAR into a TIMESTAMP
'20' || substr("Message_Time",2,15) || '000',
'YYYYMMDDHHMISSNNNNNN')
) as "Date",
"Message_Location", "Service_Name_U",
"Operation_Name_U", "Port_Namespace_U",
"Error_Code_U", "Error_SubCode_U", "Fault_Code_U", "Fault_String_U",
"Requester_Identity", "Application_ServerName_U"
from "Fault_Log_Table_610"
where "Message_Time" >= 1181016220000000
and "Message_Time" < 1181017220000000
and "Operation_Name_U" = 'getDomandeDisabile'
)
select
"Date",
count(*) as "Fault",
"Message_Location", "Service_Name_U",
"Operation_Name_U", "Port_Namespace_U",
"Error_Code_U", "Error_SubCode_U", "Fault_Code_U", "Fault_String_U",
"Requester_Identity", "Application_ServerName_U"
from x
group by "Date",
"Service_Name_U", "Operation_Name_U", "Error_Code_U", "Error_SubCode_U",
"Message_Location", "Fault_Code_U", "Fault_String_U",
"Port_Namespace_U", "Requester_Identity", "Application_ServerName_U"