--对输入的数据进行约束
create table t(studentID char(10), [name] varchar(8),
startDate char(10) Check (isdate(startdate)=1 and cast(startdate as datetime)=convert(datetime,startdate,120)))
insert into t
select 'aa','bb','77799820'
union all select 'bb','ggg','2007-10-11'
union all select 'cc','ddd','2007-20-11'
select * from t
--创建测试表
create table tbl ([name] varchar(8), chinese float, math float,zong float,px int)
insert tbl
select 'a', 80, 90,null,null
union all select 'b', 85, 88,null,null
union all select 'c', 77, 93,null,null
union all select 'd', 80, 90,null,null
union all select 'e', 99, 100,null,null
--另一种方法
select *,zong=chinese + math,
px=(select count(1)+1 from tbl b where b.chinese + b.math >a.chinese + a.math )
from tbl a order by px,chinese

--创建存储过程
create proc mysql
as
update bb set zong=tt.zong,px=tt.px from tbl bb,
(SELECT name,zong , px=(SELECT COUNT(zong) FROM
(
select name,chinese,math,zong = chinese + math from tbl
) t
WHERE zong > a.zong or (zong = a.zong and chinese > a.chinese)) + 1
FROM
(
select name,chinese,math,zong = chinese + math from tbl
) a
) tt
where bb.name=tt.name
go
--调用存储过程
exec mysql
--查看
select * from tbl

--删除
drop table tbl
drop proc mysql

--创建表
create table tb(ID int,TEAM varchar(10),SCORE int,SCORE2 int,SCORE3 int)
insert into tb values(1, 'A ', 100 , 100 , 100)
insert into tb values(2, 'A ', 90 , 100 , 100)
insert into tb values(3, 'B ', 50 , 40 , 30 )
insert into tb values(4, 'B ', 50 , 40 , 30)
insert into tb values(5, 'A ', 90 , 100 , 80)
insert into tb values(6, 'B ', 55 , 50 , 50)
insert into tb values(7, 'A ', 90 , 100 , 50)

--查询
select *,px=(select count(1)+1 from tb
where team=a.team and (score >a.score)
or (score = a.score and score2 >a.score2)
or (score = a.score and score2=a.score2 and score3 >a.score3)
or (score = a.score and score2=a.score2 and score3=a.score3 and id <a.id))
from tb a order by team

--删除
drop table tb

MySQL之学生名次问题的更多相关文章

  1. MySQL(学生表、教师表、课程表、成绩表)多表查询

    1.表架构 student(sid,sname,sage,ssex) 学生表 course(cid,cname,tid) 课程表 sC(sid,cid,score) 成绩表 teacher(tid,t ...

  2. mysql 获取学生个人科目平均分

    mysql> select * from test; +----+----------+-------+-----------+ | id | name | score | subject | ...

  3. 【MySQL】学生成绩

    统计每个人的总成绩排名 select stu.`name`,sum(stu.score) as totalscore from stu GROUP BY `name` order by totalsc ...

  4. 「艺蜂酒店管理系统」 · Java Swing + mysql 开发 学生毕业设计项目

    Java  Swing在社会上基本用不到,但是任有学校拿来当做结课设计,只是博主在校期间的一个项目.如果在部署过程中有问题可以加我qq68872185. 码云仓库地址:https://gitee.co ...

  5. 利用JDBC连接MySQL并使用MySQL

    driver为JDBC的驱动. url为数据库的地址. usrname和password分别为数据库的用户名和密码. Connection类用来连接MySQL. PreparedStatement类用 ...

  6. mysql中常用的公式及个人演示

    学生,院系表 -- phpMyAdmin SQL Dump-- version 4.1.9-- http://www.phpmyadmin.net---- Host: localhost-- Gene ...

  7. MySQL 多表结构的创建与分析

    =====================多对一===================== create table press( id int primary key auto_increment, ...

  8. MySQL中间件之ProxySQL(8):SQL语句的重写规则

    返回ProxySQL系列文章:http://www.cnblogs.com/f-ck-need-u/p/7586194.html 1.为什么要重写SQL语句 ProxySQL在收到前端发送来的SQL语 ...

  9. ORM版,学生信息管理单表查询..

    mysql 建学生表及课程表 添加内容 view.py from django.shortcuts import render,HttpResponse,redirect from . import ...

随机推荐

  1. python学习进阶一

    map()函数 def format_name(s): return s.capitalize() print map(format_name, ['adam', 'LISA', 'barT']) R ...

  2. 把自定义类实例存储到LSO

    使用flash.net.registerClassAlias( )方法保留类型信息并把类实例添加到共享对象的data属性上. LSOs 使用特殊的二进制格式,Action Message Format ...

  3. Android应用集成支付宝接口的简化

    拿到支付宝接口的andriod demo后有点无语,集成一个支付服务而已,要在十几个java类之间引用来引用去,这样不仅容易导致应用本身代码结构的复杂化,调试起来也很累,于是操刀改造之: 该删的删,该 ...

  4. 专注网格剖分 - TetGen

    提要 记得大三那一年有一门课叫做高等有限元,最后的作业就是网格剖分算法的实现,我和同学一起花了些时间做了一个Qt程序,他写算法,我写界面,最后成绩竟然出奇的拿了90多... 今天要介绍的这款软件Tet ...

  5. 能在你离开时照顾你的宠物的3D打印机器人

    您的宠物很可爱吧,您要离开时怎么办?找宠物公司来照顾他们?现在不用了.加拿大大学生推出了其3D打印的宠物机器人PetBot,它能照顾您的宠物,让您远程监控宠物,并能让您和宠物互动. “有 些人认为宠物 ...

  6. 开始研究Ray tracing

    几个月前面试时Boss问过我一个问题--"除了scanline渲染方法,你还知道什么其他渲染方式?",我没答出来,至今记忆犹新. 前段时间摆弄Intel VTune时看了它的示例代 ...

  7. ubuntu14 部署zookeeper3.4.6启动失败

    解压缩zookeeper,启动时,报如下错误: zkServer.sh: 81: /home/xxx/zookeeper-3.4.6/bin/zkEnv.sh: Syntax error: " ...

  8. FlatUI博皮制作

    Bootstrap3出来了,抛开内部框架结构和css命名的变化,bs3最大的改变莫过于扁平化. 扁平化UI中的典范,除了Metro,就是Flat了.目前本人FlatUI中毒中,于是开始慢慢的开始将博皮 ...

  9. Android获取网页上的图片的代码

    public Bitmap getWebBitmap(String imgUrl) { Bitmap bitmap =null; try { InputStream inputStream = nul ...

  10. Xutils3的使用

    Xutils是前两年很火的一个三方库(githup地址),是一个工具类,分为4个模块:DbUtils.HttpUtils.ViewUtils. BitmapUtils,还有一个非常使用功能就是LogU ...