当前位置:数据库 > MySQL >>

求解一个mysql数据库查询问题

答案:这段sql是根据要求分段: select case when a>100 then 30 when a>50 and a<=100 then 20 when a>0 and a<=50 then 10 when a=0 then 0 end as a,case when b>10 then 30 when b>5 and b<=10 then 20 when b>0 and b<=5 then 10 when b=0 then 0 end as b,case when c>3 then 30 when c>1 and c<=3 then 20 when c>0 and c<=1 then 10 when c=0 then 0 end as c from score 之后就是将分段了的结果,取和就是了 至于最后的sql,你可以复制上去试一下,应该可以达到你的需求: select a,b,c,(aaa+bbb+ccc) as 总分 from (select a,b,c,case when a>100 then 30 when a>50 and a<=100 then 20 when a>0 and a<=50 then 10 when a=0 then 0 end as aaa,case when b>10 then 30 when b>5 and b<=10 then 20 when b>0 and b<=5 then 10 when b=0 then 0 end as bbb,case when c>3 then 30 when c>1 and c<=3 then 20 when c>0 and c<=1 then 10 when c=0 then 0 end as ccc from score) as books

上一个:将现有mssql备份文件导入到mysql数据库
下一个:我在服务器上可以通过mysql命令行登陆并查询数据库,但phpcms,ecshop都说mysql没有安装.

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,