我正在尝试将数据插入具有以下行的daily_stats
表中
submission_date
message_class
channel
data_centre
line_of_business
submission_vol
从Payld_Data.Received_Messages
表开始,但我希望我的脚本仅在脚本运行的那一天每天在消息中插入数据
我在下面写了一些内容,但是如何添加日期,使其仅添加到每天收到的邮件中?
insert into daily_stats values (trunc(submission_date), Message_Class, Channel, data_centre, Line_Of_Business, submission_vol(*))
Select trunc(A.submission_date), A.Message_Class, A.Channel, A.Data_Centre, B.Line_Of_Business, submission_vol(*)
From Payld_Data.Received_Messages A, Recon_Data.Reconciliation_Control B
Where A.Conversation_Id = B.Conversation_Id
group by Trunc(A.Creation_Timestamp), A.Message_Class, A.Channel, A.Data_Centre, B.Line_Of_Business;
答案 0 :(得分:0)
我在这里有点猜测,因为您的问题还不清楚,您的Submission_Date
应该是当前日期(运行此INSERT语句的日期。如果是这种情况,请执行以下操作应该工作:
insert into daily_stats (submission_date, Message_Class, Channel, data_centre, Line_Of_Business, submission_vol(*))
Select CURRENT_DATE, A.Message_Class, A.Channel, A.Data_Centre, B.Line_Of_Business, submission_vol(*)
From Payld_Data.Received_Messages A, Recon_Data.Reconciliation_Control B
Where A.Conversation_Id = B.Conversation_Id
group by Trunc(A.Creation_Timestamp), A.Message_Class, A.Channel, A.Data_Centre, B.Line_Of_Business;
这里最大的变化是
CURRENT_DATE
获取当前日期INSERT INTO <table> (List, Of, Fields)
格式是编写此代码的正确方法,请注意在字段列表之前没有VALUE
。TRUNC()
函数,因为这纯粹是一个字段列表,不允许进行转换/逻辑。在查询的SELECT
部分中,您可以执行Trunc()
和其他逻辑。 INSERT
部分仅用于指定我们要插入哪个表以及哪些字段(及其顺序)。您可以检出Insert... Select
的{{3}}语句以查看正确的语法。