MySQL TIMESTAMPDIFF函数不返回预期结果

时间:2016-10-10 07:06:06

标签: mysql

SELECT
  M.strMemID                                          AS 'Member ID',
  M.strMemLastname                                    AS 'Last Name',
  M.STRMEMFIRSTNAME                                   AS 'First Name',
  M.strMemMiddlename                                  AS 'Middle Name',
  TIMESTAMPDIFF(YEAR, m.dtmMemBirthday, CURRENT_DATE) AS 'Age'
FROM TBLMEMBER M
WHERE m.strMemID NOT IN (SELECT DISTINCT m.strmemid
                         FROM tblmember m, tblmemberministry mm, tblpositionmemberministry pmm
                         WHERE m.strMemID = mm.strMMMemID AND mm.strmemmincode = pmm.strpmmmemmincode AND (
                           pmm.strPMMCode = 'POS041' OR PMM.STRPMMCODE = 'POS009' OR PMM.STRPMMCODE = 'POS010' OR
                           PMM.STRPMMCODE = 'POS012' OR PMM.STRPMMCODE = 'POS017' OR PMM.STRPMMCODE = 'POS021' OR
                           PMM.STRPMMCODE = 'POS028' OR PMM.STRPMMCODE = 'POS031' OR PMM.STRPMMCODE = 'POS037' OR
                           PMM.STRPMMCODE = 'POS039') AND mm.dtmMMDateQuit IS NULL AND pmm.dtmpmmdateto IS NULL AND
                               TIMESTAMPDIFF(YEAR, m.dtmMemBirthday, CURRENT_DATE) > 30);

这是我的代码。请忽略令人困惑的子查询。我的目标是显示age > 30成员。我正在使用TIMESTAMPDIFF。但是这个查询以及年龄在30岁以下的人都会返回。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我的坏人。我没有看到我的TIMESTAMPDIFF(YEAR, m.dtmMemBirthday, CURRENT_DATE) > 30在我的子查询中。现在解决了!不管怎样,谢谢。