Projection 中的所有列都在 Group By 中。
SELECT registryno ,
registrystatus ,
psPatRegisters.pattrantype ,
PK_psPatRegisters ,
payername
FROM psPatRegisters ,
psPatinv
WHERE psPatRegisters.PK_psPatRegisters = psPatinv.FK_psPatRegisters
AND registryno BETWEEN '7133' AND '7169'
AND psPatinv.pattrantype = 'I'
GROUP BY registryno ,
registrystatus ,
psPatRegisters.pattrantype ,
PK_psPatRegisters ,
payername
或使用DISTINCT
关键字
SELECT
DISTINCT
registryno ,
registrystatus ,
psPatRegisters.pattrantype ,
PK_psPatRegisters ,
payername
FROM psPatRegisters ,
psPatinv
WHERE psPatRegisters.PK_psPatRegisters = psPatinv.FK_psPatRegisters
AND registryno BETWEEN '7133' AND '7169'
AND psPatinv.pattrantype = 'I'
我认为如果您只想从结果中删除重复值,最好的方法是使用DISTINCT
,但如果您想使用聚合函数(如 Sum/Min/...),您最常使用Group By