将标记转换为百分比

时间:2012-08-13 13:59:46

标签: sql vb.net sql-server-2005

如何将学生获得的分数转换为x% 即有两门考试。计算两次考试中的某些%分数(比如说x%和Y%),这样总数就会达到100%

1 个答案:

答案 0 :(得分:1)

根据您提供的有限信息,我认为您可能会要求以下内容:

create table student
(
    id int,
    s_name varchar(10)
)
insert into student values (1, 'Jim')
insert into student values (2, 'Bob')
insert into student values (3, 'Jane')

create table exams
(
    id int,
    e_name varchar(10)
)
insert into exams values (1, 'Test 1')
insert into exams values (2, 'Test 2')
insert into exams values (3, 'Test 3')
insert into exams values (4, 'Test 4')

create table exam_student
(
    e_id int,
    s_id int,
    dt datetime,
    score decimal(5,2)
)
insert into exam_student values(1, 1, '2012-08-01', 65.0)
insert into exam_student values(1, 2, '2012-08-01', 85.0)
insert into exam_student values(2, 1, '2012-08-02', 75.0)
insert into exam_student values(2, 2, '2012-08-02', 42.0)


select avg(es.score) as ScorePct, s_id, s.s_name
from exam_student es
inner join exams e
    on es.e_id = e.id
inner join student s
    on es.s_id = s.id
group by s_id, s_name

结果:

enter image description here

如果您提供有关您正在寻找的确切内容的更多详细信息,这将有助于回答您的问题。