以上为执行语句后截图
建了以下两个表
CREATE TABLE dgclientdata(id NUMBER(7) CONSTRAINT table_id_nn NOT NULL,date_time VARCHAR2(40),client_mac VARCHAR2(15),adver_id VARCHAR2(15),CONSTRAINT table_pk PRIMARY KEY (date_time,client_mac,adver_id));
CREATE TABLE countend(mdate VARCHAR2(15), adver_id VARCHAR2(15), clicks NUMBER(7),CONSTRAINT countend_pk PRIMARY KEY (mdate,adver_id));
表中有数据,现执行
插入语句:
INSERT INTO countend select date_time,adver_id,count(*) from dgclientdata group by adver_id having date_time=to_char(sysdate-1);
这条插入语句哪里出错?
------最佳解决方案--------------------
INSERT INTO countend select distinct date_time,adver_id,count(*) over ( partition by adver_id) from dgclientdatawhere date_time=to_char(sysdate-1);
加一个distinct就好 ------其他解决方案--------------------
INSERT INTO countend
select date_time,adver_id,count(*) over ( partition by adver_id)
from dgclientdata
where date_time=to_char(sysdate-1);
------其他解决方案-------------------- group by 错误,select data_time,adver_id,count(*) from dgcclientdate group by adver_id;这句sql错误,以adver_id分组,只能查询adver_id 和聚合函数。即:select adver_id,count(*) from dgcclientdate group by adver_id,去掉data_time ------其他解决方案--------------------