带有group by的SQL插入查询

时间:2018-06-14 14:32:58

标签: sql

尝试运行以下查询它不会有任何想法如何编写它?

insert into daily_stats values (trunc(creation_timestamp), Message_Class, Channel, data_centre, Line_Of_Business, count(*))
    Select trunc(A.Creation_Timestamp), A.Message_Class, A.Channel, A.Data_Centre, B.Line_Of_Business, Count(*) 
    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;

1 个答案:

答案 0 :(得分:0)

您不能使用值并同时选择。

删除VALUES并将其替换为您插入表中的列名(我更新了它,假设列名称,因此您可能需要更改它们)

insert into daily_stats (creation_timestamp, Message_Class, Channel, data_centre, Line_Of_Business, ColumCount)
    Select trunc(A.Creation_Timestamp), A.Message_Class, A.Channel, A.Data_Centre, B.Line_Of_Business, Count(*) 
    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;