当前位置: 首页 > 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;

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • linux证书生成详解
  • 堆的实现(偷懒版)
  • DVWA DOM Based Cross Site Scripting (DOM型 XSS)
  • 第三方jar自带logback导致本地日志文件不生成
  • 前端(HTML + CSS)小兔鲜儿项目(仿)
  • CSS3下拉菜单实现
  • windows 版本Jenkins的Jenkinsfile中共享变量
  • 数据结构--第七天
  • 【AI绘图】基于Midjourney开发的AI绘画平台,对中文很友好!
  • Ubuntu文件操作(压缩与解压缩、用户组管理、权限)
  • 鸿蒙应用服务开发【华为支付服务】客户端
  • 剖析算法内部结构----------贪心算法
  • Arduino编译时出现extra tokens at end of #ifndef directive
  • 智能输电线路防外破监测装置:监控线行下施工保持安全距离
  • 一个简单的录音软件(利用QT录音,ffmpeg进行音频重采样,fdk-aac编码)
  • hadoop集群管理系统搭建规划说明
  • leetcode讲解--894. All Possible Full Binary Trees
  • 观察者模式实现非直接耦合
  • 将回调地狱按在地上摩擦的Promise
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 前端自动化解决方案
  • 区块链将重新定义世界
  • 实战:基于Spring Boot快速开发RESTful风格API接口
  • 使用 Xcode 的 Target 区分开发和生产环境
  • 使用common-codec进行md5加密
  • 小试R空间处理新库sf
  • 一起来学SpringBoot | 第十篇:使用Spring Cache集成Redis
  • C# - 为值类型重定义相等性
  • 分布式关系型数据库服务 DRDS 支持显示的 Prepare 及逻辑库锁功能等多项能力 ...
  • ​​​​​​​开发面试“八股文”:助力还是阻力?
  • ​【C语言】长篇详解,字符系列篇3-----strstr,strtok,strerror字符串函数的使用【图文详解​】
  • ​queue --- 一个同步的队列类​
  • ​人工智能书单(数学基础篇)
  • ​香农与信息论三大定律
  • #define、const、typedef的差别
  • #php的pecl工具#
  • #VERDI# 关于如何查看FSM状态机的方法
  • ${factoryList }后面有空格不影响
  • (C#)Windows Shell 外壳编程系列4 - 上下文菜单(iContextMenu)(二)嵌入菜单和执行命令...
  • (C语言)输入自定义个数的整数,打印出最大值和最小值
  • (LeetCode) T14. Longest Common Prefix
  • (PHP)设置修改 Apache 文件根目录 (Document Root)(转帖)
  • (二)JAVA使用POI操作excel
  • (二十一)devops持续集成开发——使用jenkins的Docker Pipeline插件完成docker项目的pipeline流水线发布
  • (附源码)python旅游推荐系统 毕业设计 250623
  • (附源码)ssm高校运动会管理系统 毕业设计 020419
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (转) ns2/nam与nam实现相关的文件
  • (转)大道至简,职场上做人做事做管理
  • (自用)gtest单元测试
  • **PyTorch月学习计划 - 第一周;第6-7天: 自动梯度(Autograd)**
  • .Net CoreRabbitMQ消息存储可靠机制
  • .NET Framework Client Profile - a Subset of the .NET Framework Redistribution
  • .NET 材料检测系统崩溃分析
  • .net 验证控件和javaScript的冲突问题