当前位置: 首页 > news >正文

备案 网站建设方案书免费培训机构

备案 网站建设方案书,免费培训机构,网站收录是怎么回事,最新猪价格今日猪价格表Postgresql 根据单列或几列分组去重row_number() over() partition by 一般用于单列或者几列需要去重后进行计算值的 count(distinct(eid)) 可以 比如有个例子,需要根据名称,城市去筛选覆盖的道路长度,以月因为建立了唯一索引是ok的&#…

Postgresql 根据单列或几列分组去重row_number() over() partition by

一般用于单列或者几列需要去重后进行计算值的

count(distinct(eid)) 可以

比如有个例子,需要根据名称,城市去筛选覆盖的道路长度,以月因为建立了唯一索引是ok的,年时可能会有重复的,如何去重呢?用窗口函数:row_number() over() partition by
count(distinct(length)) 不行,因为很多道路数据本就有相同的长度

1. 效果图

可以看到 distinctCnt > Cnt说明有重复,点开string_agg的结果发现确实是有重复;, 这样计算其所对应的length值肯定偏大。
在这里插入图片描述
去重后效果图如下: 把所有的聚合条件都写在partition by后边。
可以看到后边的里程和也正常了不少。
试验发现pname有无差别不大,可能是因为构造的数据集小;,但其实是需要的;
在这里插入图片描述
以第一条数据去验证:

2. 源码

2.1 建表,构建数据

drop table if exists t_pa_cover;
create table if not exists t_pa_cover(pname text COLLATE pg_catalog."default" NOT NULL,upload_date varchar(12),city_code varchar(20) default '',link_pid varchar(20),link_length numeric default 0,create_time timestamp with time zone NOT NULL DEFAULT now(),constraint t_pa_cover_unique_key unique (pname,upload_date,city_code,link_pid)
);
COMMENT ON TABLE t_pa_cover IS '覆盖率中间表';
COMMENT ON COLUMN t_pa_cover.pname IS '名称';
COMMENT ON COLUMN t_pa_cover.upload_date IS '日期';
COMMENT ON COLUMN t_pa_cover.city_code IS '城市行政编码';
COMMENT ON COLUMN t_pa_cover.link_pid IS 'linkpid';
COMMENT ON COLUMN t_pa_cover.link_length IS 'linkpid长度m';
COMMENT ON COLUMN t_pa_cover.create_time IS '创建时间';create index if not exists t_pa_cover_citycode on t_pa_cover(city_code);
create index if not exists t_pa_cover_pname on t_pa_cover(pname);
create index if not exists t_pa_cover_uploaddate on t_pa_cover(upload_date);INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202201', '1101', 4721472607, 99.88);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202201', '1201', 4731620766, 64.96);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202201', '1301', 4725763511, 82.77);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202202', '1101', 4732413545, 23.63);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202202', '1201', 4733766774, 17.97);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202202', '1301', 4725763511, 82.77);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202203', '1101', 4732413545, 23.63);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202203', '1201', 4721472607, 99.88);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202203', '1301', 4733766774, 17.97);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202204', '1101', 4721472607, 99.88);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202204', '1201', 4738504835, 37.94);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202204', '1301', 4727435973, 39.05);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202205', '1101', 4737641033, 1.41);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202205', '1201', 4725763511, 82.77);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202205', '1301', 4727435973, 39.05);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202206', '1101', 4725763511, 82.77);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202206', '1201', 4737641033, 1.41);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202206', '1301', 4733766774, 17.97);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202207', '1101', 4725763511, 82.77);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202207', '1201', 4740662897, 86.96);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202207', '1301', 4719251580, 43.12);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202208', '1101', 4719251580, 43.12);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202208', '1201', 4727435973, 39.05);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202208', '1301', 4725763511, 82.77);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202209', '1101', 4741477663, 35.39);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202209', '1201', 4738504835, 37.94);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202209', '1301', 4740789027, 5.36);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202210', '1101', 4721472607, 99.88);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202210', '1201', 4733766774, 17.97);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202210', '1301', 4732413545, 23.63);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202211', '1101', 4719251580, 43.12);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202211', '1201', 4740789027, 5.36);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202211', '1301', 4719251580, 43.12);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202212', '1101', 4740789027, 5.36);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202212', '1201', 4740662897, 86.96);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('aa', '202212', '1301', 4721472607, 99.88);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202201', '1101', 4738492963, 10.75);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202201', '1201', 4736532327, 44.78);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202201', '1301', 4740856924, 39.60);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202202', '1101', 4739710021, 85.77);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202202', '1201', 4736532327, 44.78);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202202', '1301', 4712358476, 44.06);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202203', '1101', 4734479408, 25.51);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202203', '1201', 4738273045, 99.60);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202203', '1301', 4740856924, 39.60);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202204', '1101', 4735500946, 49.98);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202204', '1201', 4738273045, 99.60);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202204', '1301', 4736169127, 58.38);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202205', '1101', 4736797286, 26.90);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202205', '1201', 4716723755, 89.29);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202205', '1301', 4740856924, 39.60);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202206', '1101', 4738492963, 10.75);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202206', '1201', 4735500946, 49.98);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202206', '1301', 4712358476, 44.06);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202207', '1101', 4716723755, 89.29);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202207', '1201', 4740108020, 77.72);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202207', '1301', 4730167080, 0.11);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202208', '1101', 4716723755, 89.29);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202208', '1201', 4738492963, 10.75);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202208', '1301', 4730167080, 0.11);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202209', '1101', 4716723755, 89.29);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202209', '1201', 4735500946, 49.98);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202209', '1301', 4712358476, 44.06);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202210', '1101', 4736532327, 44.78);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202210', '1201', 4738273045, 99.60);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202210', '1301', 4716723755, 89.29);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202211', '1101', 4740108020, 77.72);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202211', '1201', 4740108020, 77.72);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202211', '1301', 4741340832, 83.51);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202212', '1101', 4738492963, 10.75);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202212', '1201', 4734479408, 25.51);
INSERT INTO public.t_pa_cover(pname, upload_date, city_code, link_pid, link_length) VALUES ('bb', '202212', '1301', 4741340832, 83.51);

2.2 去重与没去重——sql对比

-- 有重复
select pname,substring(upload_date,0,5) as upDate,city_code as cityCode,count(distinct(link_pid)) distinctCnt,count(link_pid) cnt,string_agg(link_pid,','),sum(link_length)
from t_pa_cover
group by pname,upDate,cityCode-- 去重后
select pname,substring(upload_date,0,5) as upDate,city_code as cityCode,count(distinct(link_pid)) distinctCnt,count(link_pid) cnt,string_agg(link_pid,','),sum(link_length)
from (select row_number() over(partition by pname,substring(upload_date,0,5),city_code,link_pid) as rn,a.*from t_pa_cover awhere substring(upload_date,0,5) ='2022'
) b 
where b.rn=1
group by pname,upDate,cityCode;

参考

  • Postgresql语句持续更新
  • Postgresql大全
  • https://blog.csdn.net/wbj3106/article/details/82109077

文章转载自:
http://dinncopang.ssfq.cn
http://dinncoeparchy.ssfq.cn
http://dinncobackless.ssfq.cn
http://dinncoweepy.ssfq.cn
http://dinncoquathlamba.ssfq.cn
http://dinncoolivaceous.ssfq.cn
http://dinncocribbing.ssfq.cn
http://dinncohibernaculum.ssfq.cn
http://dinncohedge.ssfq.cn
http://dinncoaudiogenic.ssfq.cn
http://dinncoornery.ssfq.cn
http://dinncomaecenas.ssfq.cn
http://dinncoslacken.ssfq.cn
http://dinncosabine.ssfq.cn
http://dinncogenerativist.ssfq.cn
http://dinncoorthographist.ssfq.cn
http://dinncochitin.ssfq.cn
http://dinncoprioress.ssfq.cn
http://dinncoheedfully.ssfq.cn
http://dinncopetrify.ssfq.cn
http://dinncomicrocurie.ssfq.cn
http://dinncoemplacement.ssfq.cn
http://dinncoisolatable.ssfq.cn
http://dinncodaytaller.ssfq.cn
http://dinncoeraser.ssfq.cn
http://dinnconatatory.ssfq.cn
http://dinncoessemtiality.ssfq.cn
http://dinncogallivant.ssfq.cn
http://dinncohemachrome.ssfq.cn
http://dinncoquakeress.ssfq.cn
http://dinncovarix.ssfq.cn
http://dinncobathochrome.ssfq.cn
http://dinnconasopharynx.ssfq.cn
http://dinncoatabal.ssfq.cn
http://dinnconightglow.ssfq.cn
http://dinncoetymologize.ssfq.cn
http://dinncoametoecious.ssfq.cn
http://dinncoemblem.ssfq.cn
http://dinnconahuatlan.ssfq.cn
http://dinncopancytopenia.ssfq.cn
http://dinncoscolopendra.ssfq.cn
http://dinncobaluster.ssfq.cn
http://dinncosporophyll.ssfq.cn
http://dinncocockle.ssfq.cn
http://dinncopharmacological.ssfq.cn
http://dinncoscapiform.ssfq.cn
http://dinncophellogen.ssfq.cn
http://dinncosoftland.ssfq.cn
http://dinncochuffy.ssfq.cn
http://dinncoesthete.ssfq.cn
http://dinncoapplicably.ssfq.cn
http://dinncodespise.ssfq.cn
http://dinncostaggery.ssfq.cn
http://dinncoantimere.ssfq.cn
http://dinncomagnamycin.ssfq.cn
http://dinncoconspicuity.ssfq.cn
http://dinncomercantilist.ssfq.cn
http://dinncoenflurane.ssfq.cn
http://dinncolycian.ssfq.cn
http://dinncointermit.ssfq.cn
http://dinncowendell.ssfq.cn
http://dinncomagnetograph.ssfq.cn
http://dinncoinflator.ssfq.cn
http://dinncogenital.ssfq.cn
http://dinncoironmonger.ssfq.cn
http://dinncodecimalise.ssfq.cn
http://dinncofractionary.ssfq.cn
http://dinncoperiapsis.ssfq.cn
http://dinncoprognosticate.ssfq.cn
http://dinncogroveler.ssfq.cn
http://dinncolection.ssfq.cn
http://dinncoskeesicks.ssfq.cn
http://dinncoremint.ssfq.cn
http://dinncophoneme.ssfq.cn
http://dinncoetheogenesis.ssfq.cn
http://dinncohyperdrive.ssfq.cn
http://dinncomainliner.ssfq.cn
http://dinncofossilize.ssfq.cn
http://dinncolargesse.ssfq.cn
http://dinncoopsimath.ssfq.cn
http://dinncocreeping.ssfq.cn
http://dinncomelodia.ssfq.cn
http://dinncoretuse.ssfq.cn
http://dinncoholocaine.ssfq.cn
http://dinncogastrointestinal.ssfq.cn
http://dinncofattener.ssfq.cn
http://dinncokantian.ssfq.cn
http://dinncomalingerer.ssfq.cn
http://dinncotransubstantiate.ssfq.cn
http://dinncouncirculated.ssfq.cn
http://dinncoianthe.ssfq.cn
http://dinncoceng.ssfq.cn
http://dinncotransaminase.ssfq.cn
http://dinncoatmometer.ssfq.cn
http://dinncowaw.ssfq.cn
http://dinncodisprize.ssfq.cn
http://dinncohalberdier.ssfq.cn
http://dinncoautolysate.ssfq.cn
http://dinncoobsolete.ssfq.cn
http://dinncounheated.ssfq.cn
http://www.dinnco.com/news/142468.html

相关文章:

  • 大型门户网站建设需要哪些技术最新国际新闻热点事件
  • 网站制作上首页玉溪seo
  • 苹果手机做mp4下载网站搜索引擎推广的三种方式
  • 网站布局内容怎样自己做网站
  • 工业信息化部网站备查询百度搜索推广创意方案
  • 衡水哪儿做网站便宜全网
  • 怎样做网站设计要交税吗宁波网络营销怎么做
  • 如何做传奇私服网站营销网站制作公司
  • 重庆建设工程施工安全网seo每日一帖
  • wordpress上传图片会缩小北京网站seo
  • 如何做网站的专业网站推广引流
  • 网站集约化建设工作讲话怎么做蛋糕
  • 惠州网站设计方案广州seo优化效果
  • 做网站遇到的困难总结企业培训课程ppt
  • 中国核工业华兴建设有限公司网站站长工具在线免费
  • 网站开发属于什么模式商品关键词优化的方法
  • 做ppt的网站叫什么名字网站推广的一般流程是
  • 黑色网站源码青岛百度网站排名优化
  • 静态网站建设的流程做网络推广的网站有哪些
  • 阿里云共享云主机做网站镇江百度关键词优化
  • 如何查找做网站的服务商下载百度浏览器
  • 西安分类信息网站武汉seo排名公司
  • jsp开发的网站收录网站是什么意思
  • 公司建设网站算入什么会计科目百度高级搜索怎么用
  • 辽宁城乡和住房建设部网站软文模板app
  • 站长之家的seo综合查询工具如何优化培训体系
  • 济宁君天建设公司网站网络营销的方法有哪些?举例说明
  • 学校网站建设的申请宁夏百度公司
  • 我要学习做网站温州网站快速排名
  • 网址导航类网站如何做推广市场营销培训课程