Re: [問題] 如何將資料表根據另一資料表的資料作排序
※ 引述《harryjoker (我很幸福)》之銘言:
: 使用的語言是C#,資料庫是MSSQL
: 想請問如何將資料表根據另一資料表的資料作排序
: 例如有10個題目5個學生
: Score資料表有[scoreID][studentID][questionID][score]
: 用來存放每個學生每一題的分數,有50筆資料
: Totalscore資料表有[totalscoreID][studentID][score]
: 用來存放每個學生的總成績,有5筆資料
: 如果我想將學生第一題的得分根據他們的總分(不是這一題的分數喔,是總分)作排序
: 用sqldatasource取出丟到gridview裡
: 我該怎麼才能做到
: 另外,能夠同時將10個題目根據這種方式做排序嗎?
: 煩請各位指教
: 謝謝
可以用子查詢也可以用join , 我個人是比較推薦後者 .
注意 , 有一個限制是 totalscore
不能有一個 studentId 有兩個總分
單一題目的寫法
select s.questionId,s.studentId, s.score
ts.score as allScore
from score s , totalscore ts
where s.studentId = ts.studentid and s.questionId= 題目代碼
order by ts.score
如果你不指定題目 , 而要一次列出所有題目 ,
且各題目答題狀況依照總分排序的話
select s.questionId,s.studentId, s.score
ts.score as allScore
from score s , totalscore ts
where s.studentId = ts.studentid
order by s.questionId,ts.score
--
btw 要這麼做 , 請設定 totalscore.studentId 為索引,免得浪費太多時間在查詢
--
I am a person, and I am always thinking .
Thinking in love , Thinking in life ,
Thinking in why , Thinking in worth.
I can't believe any of what ,
I am just thinking then thinking ,
but worst of all , most of mine is thinking not actioning...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.133.218.161
→
01/24 22:04, , 1F
01/24 22:04, 1F
→
01/24 22:04, , 2F
01/24 22:04, 2F
推
01/24 22:37, , 3F
01/24 22:37, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):