我正在以递归方式处理下面的代码到同一个表但是收到错误
*Column 'checkinout.USERID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.*
*Column 'checkinout.CHECKTIME' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.*
SELECT CONVERT(VARCHAR,checktime, 106) gateDate, CONVERT(VARCHAR,checktime, 106) gateIn
,(
SELECT TOP 1 CONVERT(VARCHAR(5),CH001.checktime, 108)
FROM checkinout CH001
WHERE checktype ='I'
AND ch001.userid= mm001.userid
AND
(CONVERT(VARCHAR, CH001.checktime, 112) =CONVERT(VARCHAR, MM001.checktime, 112))
) timeIn
FROM checkinout MM001
WHERE userid=@empid
答案 0 :(得分:0)
SELECT CONVERT(VARCHAR,checktime, 106) gateDate, CONVERT(VARCHAR,checktime, 106) gateIn
,(
SELECT TOP 1 CONVERT(VARCHAR(5),CH001.checktime, 108)
FROM checkinout CH001
WHERE checktype ='I'
AND ch001.userid= mm001.userid
AND
(CONVERT(VARCHAR, CH001.checktime, 112) =CONVERT(VARCHAR, MM001.checktime, 112))
) timeIn
FROM checkinout MM001
WHERE userid=@empid
GROUP BY checkinout.USERID, checkinout.CHECKTIME