这是一个非常奇怪的问题。我有 3 个表,所有表都与 agent_id 上的关键关系。
现在这个查询:
select DATE_FORMAT(created_on,"%d/%m/%y") as date
from logs
where agent_id = "18"
and log_status="1"
and date_format(created_on,"%m/%y") = "12/12"
group by YEAR(created_on), MONTH(created_on), DAY(created_on) desc
完全按照它应该做的,它返回 3 行:
date
31/12/12
30/12/12
26/12/12
但是,当我加入 2 个其他表时,它会排除31/12/12
. 这是查询:
select DATE_FORMAT(l.created_on,"%d/%m/%y") as date
from logs l
join logs_rewards lr on l.id = lr.related_log_id
join agents a on a.id = l.agent_id
where l.log_status = "1"
and DATE_FORMAT(l.created_on,"%m/%y") = '12/12'
AND l.agent_id = '18'
group by YEAR(l.created_on), MONTH(l.created_on), DAY(l.created_on) desc
这返回:
date
30/12/12
26/12/12
我不知道为什么会这样。有什么帮助吗?
我试过改变AND l.agent_id = '18'
但AND a.id = '18'
结果相同。