新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
MYSQL 如果强行实现,查询逻辑会变的很复杂,不符合实际
站在用户的角度思考问题,与客户深入沟通,找到建始网站设计与建始网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站设计、成都网站制作、企业官网、英文网站、手机端网站、网站推广、域名注册、虚拟主机、企业邮箱。业务覆盖建始地区。
计算最好是在PHP里面
$data ..//比如查询结果返回给DATA 的二维数组
foreach($data as $vo){
$math[$vo['name']] = $vo['数学'];
$langue[$vo['name']] = $vo['语文'];
$englist[$vo['name']] = $vo['英语'];
}
arsort($math);
arsort($langue);
arsort($englist);
$i = 1;
foreach($math as $key=$vo){
$res[$key]['数学'] = $i;
}
$i = 1;
foreach($langue as $key=$vo){
$res[$key]['语文'] = $i;
}
$i = 1;
foreach($englistas $key=$vo){
$res[$key]['英语'] = $i;
}
select uid,max(reg) reg from testcx group by uid order by reg这个应该可以啊,你说的id和成绩对不上是神马意思?
这题目考的是关联查询、分组、排序等基础知识
1.每科的平均成绩:
select avg(grade) from stu_grade group by course;
2.每科的最高成绩及对应的学生信息:
select
B.grade,
A.*
from stu_grade as B
left join stu_info as A on B.stu_No = A.stu_No
group by B.course
order by B.grade desc limit 1;
3.每科的最低成绩及对应的学生信息:
select
B.grade,
A.*
from stu_grade as B
left join stu_info as A on B.stu_No = A.stu_No
group by B.course
order by B.grade asc limit 1;
CREATE PROCEDURE GetScRank()
BEGIN
DECLARE SigDone INT DEFAULT 0;
DECLARE Cno_ BIGINT;
DECLARE Cur1 CURSOR FOR SELECT DISTINCT Cno FROM Score;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET SigDone = 1;
OPEN Cur1;
TRUNCATE scResult;
FETCH Cur1 INTO Cno_;
WHILE NOT SigDone DO
INSERT INTO scResult (Sno,Cno,Sc) (SELECT DISTINCT Sno,Cno,Sc FROM Score WHERE Cno =Cno_ ORDER BY Sc DESC LIMIT 10);
COMMIT;
FETCH Cur1 INTO Cno_;
END WHILE;
CLOSE Cur1;
END
用游标效率应该还行吧.