我正在尝试的代码如下:
SELECT CONCAT(D.DriverFirstName,' ',D.DriverLastName)AS'Full Name',
SUM(T.EndOdometerKM-T.StartODometerKM) AS'Total KM Travelled'
FROM DRIVER AS D, TRIP AS T
WHERE D.DriverLicenceNum=T.DriverLicenceNum
GROUP BY T.DriverLicenceNum
HAVING SUM (T.EndOdometerKM-T.StartOdometerKM)>1000
ORDER BY SUM (T.EndOdometerKM-T.StartOdometerKM)ASC;
但是,我收到此错误消息:
#1630 - FUNCTION dbname.SUM does not exist.
根据其他帖子,问题通常是函数和括号(SUM (code))
之间的空格而不是(SUM(code))
,但我的问题仍然存在,没有空格。
答案 0 :(得分:0)
这种方式应该起作用
SELECT
CONCAT(D.DriverFirstName,' ',D.DriverLastName) AS 'Full Name',
SUM(T.EndOdometerKM-T.StartODometerKM) AS 'Total KM Travelled'
FROM DRIVER AS D, TRIP AS T
WHERE D.DriverLicenceNum=T.DriverLicenceNum
GROUP BY T.DriverLicenceNum
HAVING SUM(T.EndOdometerKM-T.StartOdometerKM) > 1000
ORDER BY SUM(T.EndOdometerKM-T.StartOdometerKM) ASC;