0
我有一個表tbl_usertests,我想從中檢索具有每個測試最大測試核心的用戶。根據條件從包含重複值的表中檢索最大值
注意:這裏的用戶是指唯一的usertestid。
其colums是:
pk_usertestid attemptdate uploaddate fk_tbl_tests_testid fk_tbl_users_userid testscore totalquestionsnotattempted totalquestionscorrect totalquestionsincorrect totalquestions timetaken iscurrent
數據:
1;NULL;"2010-06-24 22:48:07";"11";"3";"1";"53";"1";"21";"75";"92";"1"
2;NULL;"2010-06-25 01:21:37";"11";"4";"13";"0";"13";"62";"75";"801";"1"
3;NULL;"2010-06-25 01:21:50";"10";"4";"17";"5";"17";"53";"75";"640";"1"
4;NULL;"2010-06-25 01:24:23";"11";"4";"13";"0";"13";"62";"75";"801";"1"
5;NULL;"2010-06-25 01:24:47";"10";"4";"17";"5";"17";"53";"75";"640";"1"
6;NULL;"2010-06-25 01:36:04";"11";"5";"13";"0";"13";"62";"75";"801";"1"
7;NULL;"2010-06-25 01:47:26";"7";"5";"10";"1";"10";"49";"60";"302";"1"
我的查詢是:
SELECT max(`testscore`) , `fk_tbl_tests_testid` , `fk_tbl_users_userid` , `pk_usertestid`
FROM `tbl_usertests`
GROUP BY `fk_tbl_tests_testid`
這個查詢輸出:
max(`testscore`) fk_tbl_tests_testid fk_tbl_users_userid pk_usertestid
10 7 5 7
17 10 4 3
13 11 3 1
但問題是,如果有兩個用戶誰擁有相同的分數,它只顯示一個用戶,因爲我已經使用了group by子句。
對於。例如testid = 10我有兩個記錄(pk_usertestid 3和5),但它只顯示3。
我希望上傳日期少於其他用戶的用戶(如果兩個用戶具有相同的測試核心)。它應顯示爲usertestid = 3,因爲3上傳日期小於5. 現在它顯示3,但它是由於group by子句。
我無法構建查詢。
請幫我在這
感謝