Re: [問題] 如何將資料表根據另一資料表的資料作排序

看板Web_Design作者 (^^)時間16年前 (2010/01/24 22:03), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《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
沒測 , 純粹草擬的 如果有type error 自己修 XD
01/24 22:04, 1F

01/24 22:04, , 2F
另外有database版可以問這類問題.
01/24 22:04, 2F

01/24 22:37, , 3F
第一個想到的也是 join
01/24 22:37, 3F
文章代碼(AID): #1BN5D4uh (Web_Design)
文章代碼(AID): #1BN5D4uh (Web_Design)