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

SQL Zoo 9-.Window functions

以下数据均来自SQL Zoo

1.Show the lastNameparty and votes for the constituency 'S14000024' in 2017.(显示2017年选区“S14000024”的姓氏、政党和选票)

SELECT lastName, party, votesFROM geWHERE constituency = 'S14000024' AND yr = 2017
ORDER BY votes DESC

2.Show the party and RANK for constituency S14000024 in 2017. List the output by party.(显示2017年S14000024选区的政党和RANK。按各方列出输出)

select party,votes,rank()over(order by votes desc) rosn 
from ge 
where constituency = "S14000024" and yr = 2017 
order by party

3.Use PARTITION to show the ranking of each party in S14000021 in each year.  Include yr, party, votes and ranking (the party with the most votes is 1).(使用PARTITION显示S14000021中各参与方每年的排名。包括候选人、政党、得票和排名(得票最多的政党为1))

select yr,party,votes,rank()over(partition by yr order by votes desc) as posn 
from ge 
where constituency = "S14000021" 
order by party,yr

4.Use PARTITION BY constituency to show the ranking of each party in Edinburgh in 2017.  Order your results so the winners are shown first, then ordered by constituency.(使用分区按选区显示2017年爱丁堡各政党的排名。排序结果,首先显示获胜者,然后按选区排序)

select constituency,party,votes,
rank()over(partition by constituency order by votes desc) as posn
from ge
where yr = 2017
and constituency between 'S14000021' and 'S14000026'
order by posn,constituency

5.Show the parties that won for each Edinburgh constituency in 2017.(列出2017年爱丁堡各选区获胜的政党)

select constituency,party from 
(select constituency,party,votes,
rank()over(partition by constituency order by votes desc) posn 
from ge 
where yr = 2017 and 
constituency between "S14000021" and "S14000026") as rk 
where rk.posn = 1 
order by constituency

6.Show how many seats for each party in Scotland in 2017.(显示2017年苏格兰各党派的席位)

select a.party, count(*) seats
from (select party,rank() over(partition by constituencyorder by votes desc) as numsfrom gewhere constituency like 'S%' and yr = 2017) as a
where a.nums = 1
group by a.party;

http://www.lryc.cn/news/424945.html

相关文章:

  • 智能化清理C盘的方法 小白也可以轻松清理C盘了 不再担心误删文件
  • 在c#中常用的特性
  • Polars简明基础教程十二:可视化(二)
  • python 使用正则表达式判断图片路径是否是超链接
  • 【学习笔记】Day 14
  • 使用SSL认证访问操作手册
  • 网络协议 十一 ARP,RARP,icmp,websocket,webservice,HTTPDNS,FTP,邮件相关的协议, SMTP,POP,IMAP
  • 浏览器插件利器--allWebPluginV2.0.0.16-Stable版发布
  • 设计模式22-迭代器模式
  • 编程深水区之并发⑥:C#的线程池
  • KCTF 闯关游戏:1 ~ 7 关
  • 【海贼王航海日志:前端技术探索】一篇文章带你走进JavaScript(二)
  • 鸿蒙内核源码分析(进程管理篇) | 谁在管理内核资源?
  • SQLALchemy 自动从数据库中映射
  • C++ stack与queue的使用与简单实现
  • 【CS.DB】数据库-关系型数据库-MySQL-3.3.创建和管理表
  • Ceph分布式存储系统的搭建与使用
  • 通过Redsocks将Kali Linux的流量进行代理
  • 基于java五台山景点购票系统(源码+论文+部署讲解等)
  • 基于springboot的网上服装商城
  • QT、C++简单界面设计
  • 代码随想录算法训练营43期 | Day 10——栈与队列part1
  • Java中常用的设计模式
  • leetcode 11-20(2024.08.15)
  • C语言整数溢出的问题
  • Linux学习之路 -- 进程 -- 进程间通信 -- 管道通信
  • GB/T 38082-2019 生物降解塑料购物袋检测
  • docker数据卷和资源控制
  • Kafka系统及其角色
  • 从零开始构建霸王餐返利APP的技术路线与挑战