在 2015年5月1日之后 是 score/1.5
select sum(score)/1.2 as sum1 from student
where name="学生姓名" and date<='2015-05-01'
select sum(score)/1.5 as sum2 from student
where name="学生姓名" and date>'2015-05-01'
然后 sum1+sum2
请问这个功能 有没有一个 sql 语句来实现的
学生本来 是 120分 的试卷 后来 改成 150分的试卷了 这里的目的是把 120分折算成 100分,即 /1.2 把 150分折算成 100,即 /1.5
1)一种方法 select sum(case when date<='2015-05-01' then score/1.2 else score/1.5 end) from student where name = '学生姓名';
2)二种方法
date关键字要加反单, 时间格式比较一般都是unixtimestamp
3) 三种方法 select ((select sum(score)/1.2 as sum1 from student where name="学生姓名" and date<='2015-05-01') +
(select sum(score)/1.5 as sum2 from student where name="学生姓名" and date>'2015-05-01')) as total ;
----这样应该也行的
4)四种方法
5)五种方法 select t1.sum1+t2.sum2 from
(select sum(score)/1.2 as sum1 from student
where name="学生姓名" and date<='2015-05-01') as t1,
(select sum(score)/1.5 as sum2 from student
where name="学生姓名" and date>'2015-05-01') as t2