1. sql 語句 並列排名的問題
無論sqlserver 還是 oracle
用
rank() 或者 dens_rank() 函數。
select name,score,rank() over(order by score) tt from t;
如果有並列的話 . 他們後邊的排序會變成這樣的。 根據你的需求選用。
1
2
2
4
select name,score, dens_rank() over(order by score) tt from t;
1
2
2
3
感覺你用地2個,, dense_rank() 然後設置。 讓 虛擬的這個排序列tt<=5
2. SQL排名問題
看滾逗上去大困賣沒有錯哦
建議把別名都寫上,尺返然後再試試
update test3_01
set 排名 =
(select count(b.*)+1 from test3_01 as b
where b.總成績> a.總成績)
from test3_01 as a
3. 按照人名查出學生的各科成績以及總成績並按總成績排名的sql語句
按照人名查出學生的各科成績以及總成績並按總成績排名的sql語句示例如下:
selectA.name ,
(selectB.scorefromtable_scoreBwhereB.type='數學'andA.id=B.id) as數學 ,
(selectB.scorefromtable_scoreBwhereB.type='語文'andA.id=B.id) as語文,
(selectB.scorefromtable_scoreBwhereB.type='英語'andA.id=B.id)as英語,
(selectSUM(B.score)fromtable_scoreBwhereA.id=B.id)assum_score
fromtable_studentAorderbysum_scoreDESC
以上sql語句首先把學生表和成績表聯合查出每個學生的數學、語文、英語成績,然後通過selectSUM(B.score)fromtable_scoreBwhereA.id=B.id查出每個學生的總成績。
最後orderbysum_scoreDESC實現按總成績倒敘排列。
(3)sql排名問題擴展閱讀
上述sql語句重點是對as關鍵字的使用- Alias(別名),通過使用 SQL,可以為列名稱和表名稱指定別名(Alias)。
表的 SQL Alias 語法
SELECT column_name(s) FROM table_name AS alias_name;
列的 SQL Alias 語法
SELECT column_name AS alias_name FROM table_name;
Alias 實例: 使用表名稱別名
假設我們有兩個表分別是:"Persons" 和 "Proct_Orders"。我們分別為它們指定別名 "p" 和 "po"。
現在,我們希望列出 "John Adams" 的所有定單。
我們可以使用下面的 SELECT 語句:
SELECT po.OrderID, p.LastName, p.FirstName FROM Persons AS p, Proct_Orders AS poWHERE p.LastName='Adams' AND p.FirstName='John'
4. sql中查詢排名名次
sql語句是這樣的
select count(*) from student where class=601 and score>(select score from student where name='張三')
這個就求出了在601班的張三前有多少個人,他的名就是這個返回值+1,這個問題不關排序鳥事。做個統計就行了!
你不會是要在頁面直接調用sql語句吧!
常規方法是把這個放在一個業務類傳給數據訪問層做處理後返回結果傳給頁面
你問的response.write這個有點吃力吧!
5. sql分組 排名問題
create table #a (a char(10), b char(10),c int)
insert #a select '語文' ,'甲', 60
insert #a select '語文' , '乙' , 73
insert #a select '語文' , '丙' , 80
insert #a select '語文' , '丁' , 91
insert #a select '數學' , ' 甲' , 75
insert #a select '數學' , '乙' , 80
insert #a select '數學' , '丁' , 90
create table #e (a char(10), b char(10),c int,d int)
select distinct a into #b from #a
select identity(int,1,1) as id, a into #c from #b
declare @a int
declare @b int
select @a=min(id) from #c
select @b=max(id) from #c
while (@a<=@b)
begin
select t1.*,identity(int,1,1) as idd into #d from #a t1,#c t2 where t1.a=t2.a and t2.id=@a
insert into #e
select * from #d
drop table #d
set @a=@a+1
end
select * from #e order by a ,d desc
6. 怎麼用SQL語句查找學生的成績排名
工具/材料:以Management Studio為例。
1、首先在桌面上,點擊「Management Studio」圖標。
7. 用sql如何查詢課程成績排名呢
1、查詢「001」課程比「002」課程成績高的所有學生的學號:
SELECT * FROM tblScore ts1, tblScore ts2
WHERE ts1.stuid = ts2.stuid AND ts1.courseid = '001' AND ts2.courseid = '002
AND ts1.score > ts2.score
(7)sql排名問題擴展閱讀
查詢資料庫使用SELECT命令。 這個命令相對比較復雜。可變化樣式較多,這里分功能依次講解。
1、查詢數據表中所有數據 語法:select * from 表名。
2、查詢指定欄位的顯示 語法:select 欄位1,欄位2,... from 表名。
3、as 別名 在查詢時,默認結果顯示的欄位和表中欄位名相同,可以通過別名來修改顯示的樣式 語法:select 欄位1 as 別名,欄位2 別名,... from 表名。在給欄位起別名時,可以使用 as ,也可以直接在欄位後跟別名,省略 as 。
4、消除重復數據 在查詢數據時,查詢結果可能會有很多重復的數據,如果不想重復,可以使用 distinct 來實現去重。 語法:select distinct 欄位名 from 表名。distinct 在去重時,會比較所有的念基指定欄位,攜高逗只有完全相同時才認為是重復的。辯賣
5、帶條件查詢 where 子句 查詢數據時,需要根據不同的需求設置條件。 通過 where 子句來設置查詢條件。
參考資料
資料庫-網路
8. SQL語句算排名的問題
SQL語句算排名的問題
復雜語句的排名,要增加一個欄位來顯示順序(排名)。如果是sqlserver2005及以後的版本,可以用ROW_NUMBER() over (order by 欄位)這樣。NTILE 也可以實現排名。
你這個寫的語句,可以排序,但沒有順序號(排名)。