有一张表:
姓名 英语 语文 数学
a 62 73 84
b 72 55 85
c 88 67 61
…… …… …… ……
要求结果1:
课程 70分以上的人数
英语 ?
语文 ?
数学 ?
要求结果2:
姓名 70分以上的课程数
a ?
b ?
c ?
…… ?
结果一:
select
count(case when "英语" > 70 then 1 esle 0 end) as "英语",
count(case when "语文" > 70 then 1 esle 0 end) as "语文",
count(case when "数学" > 70 then 1 esle 0 end) as "数学",
from tbl
结果二
select “姓名”, sum("英语" + "语文" + "数学") as "课程数"
from (select
case when "英语" > 70 then 1 esle 0 end as "英语",
case when "语文" > 70 then 1 esle 0 end as "语文",
case when "数学" > 70 then 1 esle 0 end as "数学",
"姓名" as “姓名”
from tbl )t
有问题请斧正,勿喷
结果一那边。“数学”的后面要去掉逗号