2 回答
TA贡献1828条经验 获得超4个赞
CREATE DEFINER=root
@localhost
PROCEDURE countSoreP
()
BEGIN
declare less60 smallint default 0; /*x <= 60*/
declare b60a70 smallint default 0;
declare b70a80 smallint default 0;
declare b80a90 smallint default 0;
declare more90 smallint default 0;
declare countcno char(4) default '****';
SELECT cno INTO countcno FROM course WHERE cname = '离散数学';/*确定course表中有离散数学这门课*/ SELECT COUNT(*) INTO less60 FROM sc WHERE cno = '8' AND grade < 60; SELECT COUNT(*) INTO b60a70 FROM sc WHERE cno = '8' AND grade >= 60 AND grade < 70; SELECT COUNT(*) INTO b70a80 FROM sc WHERE cno = '8' AND grade >= 70 AND grade < 80; SELECT COUNT(*) INTO b80a90 FROM sc WHERE cno = '8' AND grade >= 80 AND grade < 90; SELECT COUNT(*)INTO more90 FROM sc WHERE cno = '8' AND grade >= 90; create table countScore( scorestage char(10), number smallint); insert into countscore values('x<60', less60); insert into countscore values('60<=x<70', b60a70); insert into countscore values('70<=x<80', b70a80); insert into countscore values('80<=x<90', b80a90); insert into countscore values('x>=90', more90);
END
TA贡献1851条经验 获得超3个赞
数据库是sqlserver,那假设变成语言是C#好了。数据库这里假设有2张表:Student(学生)和Course(课程),
Course表中设置Student为外键,比如学生A选择课程1,那么Course表下就产生一条数据记录(学生A, ‘课程1’);
同理学生BCDEF选择课程12345,那么对应Course表下就产生这么几条记录:
(学生B,‘课程2’),(学生C,‘课程3’),(学生D,‘课程3’),
(学生E,‘课程4’),(学生F,‘课程5’),
最后做统计处理,统计每个CourseName(课程名)被选择的次数,即Select sum(*) from Course where CourseName=''课程x‘’。
Course
|- Student
|- CourseName
前端选课的时候,需要根据学生的Id,先得到学生已经选择哪些课程,再决定学生还能选择哪些,以及还能选择多少就好了。
- 2 回答
- 0 关注
- 752 浏览
添加回答
举报