『壹』 sql計算數字差怎麼寫
建議是編寫函數做,不過非要做,也可以做的。
我建立一個測試表:
表名是testsc 就是學生成績表
SNO Number - - - - - - 學號
CNO Number - - - - - - 課程號
GRADE Number - - - - - - 成績
然後先建立一個視圖,這個視圖中求得的是所有同學的平均成績:
create view testscavg as select t1.sno as sno ,avg(t1.grade) as avggrade from testsc t1 group by t1.sno
然後求出學生平均成績最高的和最低的之差:
select max(AVGGRADE)-min(AVGGRADE) from testscavg
『貳』 sql語句如何查詢兩個值之間的差
工液局具/材料:Management Studio。
1、首先在桌面上鬧寬讓,點擊「Management Studio」圖標。
『叄』 前十條數據的分數欄位的標准差 sql語句怎麼寫~~~~~~急
對系統的標准差演算法有質疑,自己寫了個演算法,各位看看!
A表有兩列id、number
id number
1 1
2 2
---------------------------------------------------
declare @m numeric(30, 20), @n int;
declare @i int, @x numeric(30, 20), @temp numeric(30, 20);
set @n=2;
set @i=0;
set @temp=0;
select @m=AVG(number) from A where id in (select top 2 id from A);
while (@i<2)
begin
if(@i=0)
begin
select @x=number from A where id = (select top 1 id from A where id not in (select top 0 id from A));
set @temp = @temp + power(@x-@m,2);
select @temp;
end
else if (@i=1)
begin
select @x=number from A where id = (select top 1 id from A where id not in (select top 1 id from A));
set @temp = @temp + power(@x-@m,2);
end
set @i = @i+1;
end
set @temp = @temp/@n;
declare @result numeric(30, 20)
set @result = sqrt(@temp);
select @result;
計算前二條數據
結果:0.5
系統函數計算結果:0.707106781186548
『肆』 SQL在學生表中查詢每個人的總分與平均總學分的差,要求顯示學號、姓名、專業、總學分、與平均總學分的差
T-SQL語句如下:
Select 學號,姓名,專業,總學分,總學分-(select avg(總學分) from [學生選課系統].[dbo].[學生表] where 專業=A.專業) as 與平均總學分的差 From [學生選課系統].[dbo].[學生表] as A
(*註:以上語句是學生與其所屬專業的平均總學分的對比,即平均總學分是按專業分開計算的)
如果不用考慮區分專業,而是直接跟全校學生的平均總學分比較的話,用下面的語句:
Select 學號,姓名,專業,總學分,總學分-(select avg(總學分) from [學生選課系統].[dbo].[學生表]) as 與平均總學分的差 From [學生選課系統].[dbo].[學生表] as A
『伍』 用SQL語句顯示班級學號成績並算出優良中差
select 班級,學號,(case when 成績擾答>90 then '優'
when 成績>銀中80 and 成鋒李山績<=90 then '良'
when 成績>60 and 成績<=80 then '中'
else '差' end) as 成績
from table_name
『陸』 SQL資料庫查詢中,怎麼查詢某一列數據的標准偏差,例如一個班級的學生的成績的標准偏差
select @avg=avg(列) from 表;
select @num=count(列) from 表;
select @exp= sqrt (sum(square(列-@avg))/(@num-1)) from 表;
print @avg,@num,@exp
其中@avg為列的平均值,@num為列數量,@exp為標准偏差
這種計算性的工作應該又外部程序完成而不是用資料庫來完成。
『柒』 SQL語句,如何求每個學生的成績與平均成績的差
不知道你具體什麼資料庫,,,可以用with as語句
;withcteas(select*
from表)
select*,
成績核碼-(selectavg(成績)fromtest)改改哪as平均成績
fromcte殲宴t
『捌』 如何用sql語句查出學生表成績小於60為不及格60-80為良好80-90為優秀
select name,case when 成績<60 then 不及格 when 成績>=60 and 成績<80 then 良好 when 成績>=0 and 成績<90 then 優秀 end as 成績情況 ,from 表名。
注意,在輸入sql語句的時候,要在英文環境下輸入。否則可能會出現代碼不識別。
『玖』 SQL得到總分最低和總分最高學生的總分差
table
no,course,score
11 3 67
select A-B from table T,(select max(score) from table ) A,(select min(score) from table) B