2012-07-26 44 views
1

有沒有辦法將選定的0或1的內容轉換爲否或是並從表底部搜索?有沒有辦法從下往上搜索mySQL行並根據參數改變結果?

UPDATE #__comprofiler 
SET cb_trainingpass = (SELECT c_passed 
FROM #__quiz_r_student_quiz 
WHERE #__quiz_r_student_quiz.c_student_id = #__comprofiler.user_id) 
WHERE EXISTS 
    (SELECT c_passed 
FROM #__quiz_r_student_quiz 
WHERE #__quiz_r_student_quiz.c_student_id = #__comprofiler.user_id); 

當用戶進行測試時,他們得到0 =未通過或1 =通過的結果。我正在發送這個字段到cb_trainingpass並希望它是(通過)或否。此外,用戶多次參加測試,並且他們的最新結果是我想要拉的,不幸的是,這個查詢拉了一個頂部或第一個結果,從來沒有找到最新的結果。

回答

1

嘗試像

UPDATE #__comprofiler 
SET cb_trainingpass = (SELECT if(c_passed=1,'yes','no') 
FROM #__quiz_r_student_quiz 
WHERE #__quiz_r_student_quiz.c_student_id = #__comprofiler.user_id 
order by #__quiz_r_student_quiz.YOURDATEFIELD desc) 
WHERE EXISTS 
    (SELECT c_passed 
FROM #__quiz_r_student_quiz 
WHERE #__quiz_r_student_quiz.c_student_id = #__comprofiler.user_id); 
+0

真棒!謝謝。 – Shane 2012-07-26 21:17:34

相關問題