我有一个查询,我尝试获取总和值,但我得到了 InvalidCastException。
我的查询是:
SELECT e.clockNr,e.firstName,e.LastName,e.unionName,i.points
FROM (
SELECT employee.clockNr AS clockNr,
employee.firstName AS firstName,
employee.lastName AS lastName,
Unions.name AS unionName
FROM employee,Unions
WHERE employee.active=1 AND employee.unionId = unions.id
GROUP BY employee.clockNr
) e LEFT JOIN (
SELECT infraction.clockNr AS clockNr,
CAST(SUM(Infraction.points) AS SIGNED) AS points
FROM infraction
WHERE infraction.infractionDate >=@startDate
AND infraction.infractionDate <=@endDate
GROUP BY infraction.clockNr
) i ON e.clockNr = i.clockNr
ORDER BY e.clockNr ASC
出错的地方是“点”列。我已将 CAST 添加到 SIGNED 中,但这无济于事。
我读出专栏的方式是:
int iGetPoints = Convert.ToInt32(reportReader["points"]);
也试过:
int iGetPoints = (int)reportReader["points"];
但两者都会引发 InvalidCastException。该查询在 PHPMyAdmin 中进行了测试,并且在那里运行良好。
谁能看到我做错了什么或给我提示在哪里寻找?