subject_inv テーブルから最も一致する科目を持つ学生のリストを取得しようとしています。私のクエリの問題は、sql_mode を変更する必要があることです。sql_mode パラメータを変更せずにこのクエリを変更する方法はありますか。
SELECT `student`.*, `subject_inv`.`subject_name`, `score`.`custom_score`,
MIN(
CASE WHEN (`student`.`subject` = `subject_inv`.`subject_name`) THEN 1 WHEN (`student`.`topic1` = `subject_inv`.`subject_name`) THEN 2 WHEN (`student`.`topic2` = `subject_inv`.`subject_name`) THEN 3 WHEN (`student`.`topic3` = `subject_inv`.`subject_name`) THEN 4 END
) AS priority
FROM `student`
LEFT OUTER JOIN `subject_inv` ON `subject_inv`.`subject_name`=`student`.`subject` OR `subject_inv`.`subject_name` = `student`.`topic1` OR `subject_inv`.`subject_name` = `student`.`topic2` OR `subject_inv`.`subject_name` = `student`.`topic3`
LEFT OUTER JOIN `score` ON `student`.`id`=`score`.`id` GROUP BY `student`.`id`, priority
次のエラーが表示されます。sql_mode を "only_full_group_by" から other に変更すると、おそらく修正されるはずです。
#1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mydb.student.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
sql_mode を変更せずにこの結果を取得する方法はありますか?
student
id | full_name | subject | topic1 | topic2 | topic3
___________________________________________________
1 | tom | sbj1 | sbj4 | |
2 | sam | sbj3 | sbj7 | |
3 | ron | sbj6 | sbj2 | |
subject_inv
id | subject_name | tutor
__________________________
1 | sbj1 | tut1
2 | sbj7 | tut2
3 | sbj4 | tut3
4 | sbj9 | tut3
score
id | custom_score
__________________
1 | 10
2 | 6
3 | 9
4 | 4
予想された結果:::
id | full_name | subject | topic1 | topic2 | topic3 | subject_name | custom_score
________________________________________________________________________________
1 | tom | sbj1 | sbj4 | | | sbj1 | 10
2 | sam | sbj3 | sbj7 | | | sbj7 | 6
3 | ron | sbj6 | sbj2 | | | NULL | 9