下面的查询为我提供了所需的结果。
SELECT *
FROM PTAddedApp
WHERE PTAddedApp.date BETWEEN '2014-12-01' AND '2015-01-13'
但是,下面的查询为我提供0个结果,或者如果我放下WHERE PTAddedApp.date = 0,我将获得所有结果,并将0000-00-00作为日期值。我已经将按钮捣碎了很多。任何帮助将不胜感激。日期列具有日期数据类型。
SELECT PTAddedApp.id,
PTAddedApp.family_id,
PTAddedApp.tid,
PTAddedApp.date,
PTAddedApp.rate,
PT_Tutors.first_name,
PT_Tutors.last_name,
PT_Family_Info2.billing_name
FROM PTAddedApp
INNER JOIN PT_Tutors
ON PTAddedApp.tid = CONCAT(PT_Tutors.first_name, ' ',
PT_Tutors.last_name)
INNER JOIN PT_Family_Info2
ON PTAddedApp.family_id = PT_Family_Info2.id
WHERE PTAddedApp.date BETWEEN '2014-12-01' AND '2015-01-13'
ORDER BY PT_Tutors.last_name
最佳答案
如果您希望包括与PTAddedApp
中的where条件匹配的所有记录以及在联接表中找到的任何其他数据,则以下方法可以解决问题!
SELECT PTAddedApp.id,
PTAddedApp.family_id,
PTAddedApp.tid,
PTAddedApp.date,
PTAddedApp.rate,
PT_Tutors.first_name,
PT_Tutors.last_name,
PT_Family_Info2.billing_name
FROM PTAddedApp
LEFT JOIN PT_Tutors
ON PTAddedApp.tid = CONCAT(PT_Tutors.first_name, ' ',
PT_Tutors.last_name)
LEFT JOIN PT_Family_Info2
ON PTAddedApp.family_id = PT_Family_Info2.id
WHERE PTAddedApp.date BETWEEN '2014-12-01' AND '2015-01-13'
ORDER BY PT_Tutors.last_name