当范围> 30天MYSQL过滤结果

时间:2014-02-11 21:43:29

标签: mysql

如果我在6月1日到6月30日之间运行查询,我会得到23个结果。如果我在7月1日到7月31日之间运行查询,我将获得28个结果。如果我从6月1日到7月31日运行查询,我只得到30个结果。这是为什么?

这是我的问题:

SELECT
    table1.user_id,
    DATE_FORMAT(table1.timestamp, '%Y-%m-%d') AS formatted_timestamp,
    COUNT(DISTINCT table1.call_id) as calls,
    SUM(table2.recording_file_duration) / 60 as minutes,
    hours.hours
FROM
    table1
LEFT JOIN table2 ON
    table1.call_id = table2.id
LEFT JOIN table3 ON
    table1.user_id = table3.accountID
    AND
    DATE_FORMAT(table1.timestamp, '%Y-%m-%d') = table3.date
WHERE
    table1.user_id = '244'
    AND
    table1.timestamp >= '$dateStart' and table1.timestamp < '$dateEnd'
GROUP BY
    DAY(table1.timestamp)
ORDER BY
    table1.timestamp DESC

0 个答案:

没有答案