当我运行此功能时
function getOpenTxCalls(date) {
return sequelize.query(
'SELECT \
CT.center_name, \
COUNT(CASE WHEN CL.disposition_type IN(3, 4, 22, 23,25, 42) AND CL."createdAt"::date = :date THEN CL.disposition_type END) AS "CallsMadeToday", \
COUNT(CASE WHEN CL.disposition_type = 3 AND CL."createdAt"::date = :date THEN CL.disposition_type END) AS "AppointmentsMadeToday" \
FROM "Centers" AS CT \
LEFT JOIN "Users" AS US ON US."centerId" = CT.id \
LEFT JOIN "CallLogs" AS CL ON CL."createdBy" = US."id" \
WHERE US."centerId" NOT IN(11, 13)\
GROUP BY CT.center_name \
ORDER BY CT.center_name',
{ replacements:
{
date: date
},
type: sequelize.QueryTypes.SELECT })
.then(function(openTXCalls) {
console.log(openTXCalls);
return openTXCalls;
})
.catch(console.log.bind(console));
}
它返回的数据不正确。
我在运行该功能时观看了CLI,并将CLI中的SQL查询复制并粘贴到PG3 Admin中,并收到了不同的(正确的)值。以下是CLI中的内容。
Executing (default): SELECT
CT.center_name,
COUNT(CASE WHEN CL.disposition_type IN(3, 4, 22, 23,25, 42) AND CL."createdAt"::date = '2016-02-17' THEN CL.disposition_type END) AS "CallsMadeToday",
COUNT(CASE WHEN CL.disposition_type = 3 AND CL."createdAt"::date = '2016-02-17' THEN CL.disposition_type END) AS "AppointmentsMadeToday"
FROM "Centers" AS CT
LEFT JOIN "Users" AS US ON US."centerId" = CT.id
LEFT JOIN "CallLogs" AS CL ON CL."createdBy" = US."id"
WHERE US."centerId" NOT IN(11, 13)
GROUP BY CT.center_name
ORDER BY CT.center_name
我在我的机器上查询同一个本地Postgres数据库。关于可能导致这种情况的任何想法?