博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据库相同成绩排名例子
阅读量:5774 次
发布时间:2019-06-18

本文共 1749 字,大约阅读时间需要 5 分钟。

数据库相同成绩排名例子

create table score1(       s_id number,       s_score decimal(5,2) --表示最大5位的数字,其中小数点后面两位小数)insert into score1 (s_id, s_score) values ('1', '3.5');insert into  score1 (s_id, s_score) values ('2', '3.65');insert into  score1 (s_id, s_score) values ('3', '4.0');insert into score1 (s_id, s_score) values ('4', '3.85');insert into  score1 (s_id, s_score) values ('5', '4.0');insert into  score1 (s_id, s_score) values ('6', '3.65');select *from score1select s_score,(select count(distinct s_score)from score1 where s_score>=s.s_score)排名 from score1 s order by s_score descselect count(distinct s_score)from score1

 查询表中排名前三的数据

Create table  Employee (Id int, Name varchar(255), Salary int, DepartmentId int);Create table  Department (Id int, Name varchar(255));select *from employeeinsert into Employee (Id, Name, Salary, DepartmentId) values ('1', 'Joe', '70000', '1');insert into Employee (Id, Name, Salary, DepartmentId) values ('2', 'Henry', '80000', '2');insert into Employee (Id, Name, Salary, DepartmentId) values ('3', 'Sam', '60000', '2');insert into Employee (Id, Name, Salary, DepartmentId) values ('4', 'Max', '90000', '1');insert into Employee (Id, Name, Salary, DepartmentId) values ('5', 'Janet', '69000', '1');insert into Employee (Id, Name, Salary, DepartmentId) values ('6', 'Randy', '85000', '1');insert into Department (Id, Name) values ('1', 'IT');insert into Department (Id, Name) values ('2', 'Sales');select *from Departmentselect d.Name as Department,e1.Name as Employee,e1.Salary from Employee e1 join Department don d.Id=e1.DepartmentId where 3>(select count(distinct e2.Salary)from Employee e2 where e2.Salary>e1.Salary and e1.departmentid=e2.departmentid)

 

转载于:https://www.cnblogs.com/tangjiang-code/p/7668393.html

你可能感兴趣的文章
经典sql
查看>>
CSS3边框会动的信封
查看>>
JavaWeb实例设计思路(订单管理系统)
查看>>
source insight中的快捷键总结
查看>>
PC-IIS因为端口问题报错的解决方法
查看>>
JavaScript学习笔记(12)——JavaScript自定义对象
查看>>
java四种线程池简介,使用
查看>>
一般处理程序(.ashx)中session的使用方法
查看>>
EasyUI笔记(二)Layout布局
查看>>
ios View之间的切换 屏幕旋转
查看>>
typedef BOOL(WINAPI *MYFUNC) (HWND,COLORREF,BYTE,DWORD);语句的理解
查看>>
jsp 特殊标签
查看>>
[BZOJ] 1012 [JSOI2008]最大数maxnumber
查看>>
使用VMware安装CentOS
查看>>
gauss消元
查看>>
多线程-ReentrantLock
查看>>
数据结构之链表与哈希表
查看>>
IIS7/8下提示 HTTP 错误 404.13 - Not Found 请求筛选模块被配置为拒绝超过请求内容长度的请求...
查看>>
http返回状态码含义
查看>>
响应式网站对百度友好关键
查看>>