从下表中,我试图选择符合以下条件的记录:
- 已在上个月内添加(无论分数如何)
- 一个多月前添加且得分 >= 10 的记录
我的努力在下面,但我哪里出错了
select id from candidates
where dateEnrolled >= date_sub(now(), interval 1 month)
and dateEnrolled <= now() and score >=10;
我一直在 7 和 8
上。正确答案应仅包含以下 ID 1 2 5 6 7 8 9 10
你能帮忙吗?
"id" "dateEnrolled" "score"
"1" "2013-01-01" "12"
"2" "2013-02-01" "15"
"3" "2013-03-01" "9"
"4" "2013-04-01" "8"
"5" "2013-05-01" "20"
"6" "2013-08-01" "0"
"7" "2013-08-12" "10"
"8" "2013-08-13" "12"
"9" "2013-08-15" "1"
"10" "2013-08-17" "5"
最佳答案
尝试类似的东西
select id from candidates where dateEnrolled >= date_sub(now(), interval 1 month)
or (dateEnrolled <= now() and score >=10);
将您的 和
选择器换成 或
。
关于mysql - 选择不到一个月前和一个月前添加的得分为 X 的所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18484803/