搜扣 sql

HAVING

1、HAVING子句中能够使用三种要素:常数,聚合函数,GROUP BY子句中指定的列名(聚合建)
用having就一定要和group by连用, 用group by不一有having(它只是一个筛选条件用的)

create table poi_20210521_orderfilter_new_duplicate as
select *
from poi_20210521_orderfilter_new
where source_id in (select source_id
                    from poi_20210521_orderfilter_new
                    group by source_id
                    having count(poi_id) > 1);


create table poi_20210521_orderfilter_new_duplicate2 as
select *
from poi_20210521_orderfilter_new_duplicate
where longitude in (
    select max(longitude)
    from poi_20210521_orderfilter_new_duplicate
    group by source_id);

delete
from poi_20210521_orderfilter_newuniq
where poi_id in (
    select poi_id
    from poi_20210521_orderfilter_new_duplicate);

insert into poi_20210521_orderfilter_newuniq
select *
from poi_20210521_orderfilter_new_duplicate2;

你可能感兴趣的:(搜扣 sql)