我对使用 AND 进行 SQL 查询有点困惑。
查询如下:
SELECT count(cdr.id) as callTotal,
sum(cdr.callDurationSeconds) as timeTotal,
users.firstname,
users.surname,
MAX(cdr.callDuration) as maxCallDuration,
AVG(cdr.answeredTime) as avgAnswerTime,
AVG(cdr.callDurationSeconds) as avgTimeTotal,
cdr.userId,
COUNT(IF(cdr.callDurationSeconds > '0', 1, NULL)) AS answeredCalls
FROM cdr
LEFT JOIN users ON cdr.userId = users.id
WHERE cdr.company = 'C47B0BCCDCE92F'
AND cdr.dateCreated LIKE '2012-11-02%'
AND cdr.userId = 'U4BC3128209B01'
OR cdr.userId = 'U4A9FCCD73C6BB'
GROUP BY userId ORDER BY users.surname ASC ;
我想按倒数第二行的日期进行查询,但随后我希望使用任何已发布的 cdr.userIds 检索项目。但是,在这种情况下,它似乎忽略了日期。我需要日期是非可选的,并在所选日期使用选择的 ID 检索任何数据。