『壹』 創建sql查詢,用SELECT語句為"成績"表各科成績做一個A,B,C的等級評分
就是一個case when語句,這個沒什麼困難的
select (case when 成績>=90 then 'A' when 成績>=80 and 成績<90 then 'B' esle 'C' end) 評級 from table
具體的內容自己改,我用的是oracle的寫法,其他資料庫也有case when語句用法差不多,如果不是oracle資料庫,那麼要自己改一改才能用。
『貳』 SQL資料庫:按成績【90,100】評『A』;【80,89】評『B』 【70,79】評『C』 【0,69】評『D』
with etc as
(
SELECT A.S# as s#,B.CNAME as cname,A.GRADE as grade FROM SC AS A JOIN C AS B
ON A.C#=B.C#)
select a.sname as 姓名,b.cname as 課程名,
(case when grade >=90 and grade <=100 then 'A'
when grade >=80 and grade <=89 then 'B'
when grade>=70 and grade<=79 then 'C'
else 'D' end) as 成績
from s as a join etc as b
on a.s#=b.s#
order by b.grade desc
『叄』 sql通過分數查詢所在等級 急急急!!!
select 員工編號,考核分數,等級=case
when 考核分數<=100 and 考核分數>=90 then '優等'
when 考核分數<=89 and 考核分數>=80 then '甲等'
when 考核分數<=79 and 考核分數>=70 then '乙等'
when 考核分數<=69 and 考核分數>=60 then '丙等'
else '丁等' end
from employee_Test
『肆』 怎樣使用sql語句可以多條件查詢 比如成績等級劃分
select sum(case when '成績'=100.0 then 1 else 0 end),
sum(case when '成績'<100 and '成績' >=90 then 1 else 0 end),
sum(case when '成績'<90 and '成績' >=80 then 1 else 0 end),
sum(case when '成績'<80.0 and '成績' >=70 then 1 else 0 end),
sum(case when '成績'<70.0 and '成績' >=60 then 1 else 0 end),
sum(case when '成績'<60 then 1 else 0 end) from table
可以按分數間隔統計出成績分布,分別是100分有多少人,90~100,80~90,70~80,60~70,60以下的區間分別有多少人。