--对输入的数据进行约束
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. Codeforces Educational Codeforces Round 3 B. The Best Gift 水题

    B. The Best Gift 题目连接: http://www.codeforces.com/contest/609/problem/B Description Emily's birthday ...

  2. Redis_字典

    阅读本文之前要了解的两件事情,第一,Redis是一种Key-Value数据库,第二,字典是一种保存键值对的抽象数据结构.所以不难猜出字典在Redis中应用一定很广泛,实际上,Redis数据库的底层实现 ...

  3. JS的加载方式---同步和异步

    同步加载及异步加载,只有这两种方式. 动态加载是异步加载的方式之一. ajax加载也是异步加载.

  4. 【JavaScript】新浪微博ajax请求后改变地址栏url,但页面不跳转的方案解析

    新浪微博当你弹出一个视频的时候再点下一页时,原视频还在,而且地址栏的url的页数变了.对于这种网上讨论最多的方案有以下几种: 一.通过锚点Hash实现在这方面其实国内很早就有做了,比如淘宝画报,通过的 ...

  5. Android横竖屏切换及其相应布局载入问题

    第一.横竖屏切换连带载入多屏布局问题: 假设要让软件在横竖屏之间切换.因为横竖屏的高宽会发生转换,有可能会要求不同的布局. 能够通过下面两种方法来切换布局: 1)在res文件夹下建立layout-la ...

  6. PERL 学习

    http://ju.outofmemory.cn/entry/193944 http://blog.sina.com.cn/s/blog_6a6c136d0101dlcw.html http://bl ...

  7. c# 高效的线程安全队列ConcurrentQueue(下) Segment类

    Segment成员变量 long long m_index; 记录该segment的索引号. int* volatile m_state; 状态数组,标识所对应的元素节点的状态,默认值为0,如果该元素 ...

  8. mysql常用备注

    一:One Table  have only one Auto_Increment that column is must to be Primary key. (自增加的字段必须是主键且是数字类型) ...

  9. NoSQL数据库的分布式算法&&memcache集群的实现

    NoSQL数据库的分布式算法  http://blog.nosqlfan.com/html/4139.html 一致性hash算法在memcache集群中的应用   http://alunblog.d ...

  10. Lambdas in Java 8--reference

    Part 1 reference:http://jaxenter.com/lambdas-in-java-8-part-1-49700.html Get to know lambda expressi ...