美文网首页
搜扣 sql

搜扣 sql

作者: hehehehe | 来源:发表于2021-05-21 11:21 被阅读0次
    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

          本文链接:https://www.haomeiwen.com/subject/iycwjltx.html