谁能帮我这个
脚本
这就是我想要实现的
桌子
id name tag_id status dob
== ======= ======== ======== ========
1 a 1 Married 02/23/1977
2 b 1 Single 02/23/1978
3 c 2 Single 02/23/1960
4 d 1 Married 02/23/1985
5 e 2 Married 02/23/1999
6 f 2 Diovice 02/23/1999
7 g 1 Married 02/28/1999
8 h 2 Married 02/28/1999
9 i 1 Married 03/12/1990
我很想用 mysql 查询得到现在/当前的生日庆祝者,这是我的代码:
SELECT * FROM table
WHERE (MONTH(STR_TO_DATE(dob, '%d/%m/%Y'))=MONTH(CURDATE())
AND (DAY(STR_TO_DATE(dob, '%d/%m/%Y'))=DAY(CURDATE())))
OR (DAY(LAST_DAY(STR_TO_DATE(dob, '%d/%m/%Y')))=29
AND (DAY(STR_TO_DATE(bob, '%d/%m/%Y'))=29)
AND (DAY(LAST_DAY(CURDATE()))=28))
AND ( STATUS = 'Married' OR STATUS = 'Single' )
AND tag_id = 1
ORDER BY id ASC
我的问题是上面的代码只是返回所有存在的 bithday 但我想要的是这样的:
结果:
1 a 1 Married 02/23/1977
2 b 1 Single 02/23/1978
4 d 1 Married 02/23/1985
7 g 1 Married 02/28/1999
错误结果(由上述查询产生):
1 a 1 Married 02/23/1977
2 b 1 Single 02/23/1978
4 d 1 Married 02/23/1985
7 g 1 Married 02/28/1999
8 h 2 Married 02/28/1999
而我想要的是,我只想要今天的生日庆祝者/ID = 1 的位置。就像我用第一个结果指定的那样。