--对输入的数据进行约束
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. JDBC-ODBC桥接方法连接Excel数据库的方法

    通过JDBC-ODBC桥接器访问Excel电子表格 1.设置数据源 Excel数据源选择的驱动程序是Microsoft Excel Driver 2.选择表 与访问其他数据库不同的是,我们必须在电子表 ...

  2. java学习路线(好资源大家分享)

    对于入门java将近两年的时间,曾经迷惘过,一直想知道java的具体学习路线,看过了许许多多的java经验分享的帖子,评论,以及其他各种培训机构所谓的学习路线,发现没有一个符合我个人需求的学习路线,根 ...

  3. Linq 学习

    聚合操作符                                                                                              说 ...

  4. WP8异常错误:Error HRESULT E_FAIL has been returned from a call to a COM component.

    在做WP8开发的过程中,使用到了longlistselector这个控件,本来使用没有问题. 但是突然出现了一个闪退的错误,错误信息如下: {MS.Internal.WrappedException: ...

  5. C# 图片裁剪代码

    /// <summary> /// 缩小裁剪图片 /// </summary> /// <param name="int_Width">要缩小裁 ...

  6. C# 仿制QQ弹出新闻消息框

    打开QQ的时候,QQ新闻弹出窗体在屏幕的右下角就会慢慢升起一个小窗口,占用的地方不大,可以起到提示的作用.下面就让我们来看看,怎样用系统API来轻松实现这个功能. API原型函数: bool Anim ...

  7. OSG 实现跟随节点的相机(转)

      本章教程将继续使用回调和节点路径(NodePath)来检索节点的世界坐标. 本章目标: 在一个典型的仿真过程中,用户可能需要从场景中的各种车辆和人物里选择一个进行跟随.本章将介绍一种将摄像机“依附 ...

  8. (转)用AGG实现高质量图形输出(二)

    本文上接<用AGG实现高质量图形输出(一)>,分别介绍了AGG显示流程中的各个环节. 上次讲了AGG的显示原理并举了一个简单的例子,这一篇文章开始讲AGG工作流程里的每个环节.为了方便对照 ...

  9. hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)

    pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/ ...

  10. android设置动态壁纸 (Wallpaper) 介绍

    当进入改壁纸的设置页面 但是还没有设置时 09-21 07:55:05.575: INFO/System.out(1337): service onCreate09-21 07:55:05.614: ...