SELECT MAX(R.Stage),D.CarID,D.RecordID FROM Repayinfo as R,CustomerBaseInfo as C,CustomerCarInfo as D where R.RecordID=C.RecordID and C.Address like '%城区%' and  R.RepayKind='CarLoan' GROUP BY D.CarID ORDER BY D.CarID不好意思,看一下线在这一句,在查询分析器中出现下面错误提示服务器: 消息 8120,级别 16,状态 1,行 1
列 'D.RecordID' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。

解决方案 »

  1.   

    SELECT MAX(R.Stage),D.CarID 
    FROM Repayinfo as R,CustomerBaseInfo as C,CustomerCarInfo as D 
    where R.RecordID=C.RecordID and C.Address like '%城区%' and  R.RepayKind='CarLoan' 
    GROUP BY D.CarID 
    ORDER BY D.CarID--没问题啊,你仔细看看表结构
      

  2.   

    SELECT MAX(R.Stage),D.CarID,D.RecordID FROM Repayinfo as R,CustomerBaseInfo as C,CustomerCarInfo as D where R.RecordID=C.RecordID and C.Address like '%城区%' and  R.RepayKind='CarLoan' 
    GROUP BY D.CarID ,D.RecordID  --notice
    ORDER BY D.CarID
      

  3.   

    提示已经很明白,就是要将d.recordid包含在函数或放在group by 语句中SELECT MAX(R.Stage),D.CarID,max(D.RecordID)--加上函数
     FROM Repayinfo as R,CustomerBaseInfo as C,CustomerCarInfo as D 
     where R.RecordID=C.RecordID and C.Address like '%城区%' and     R.RepayKind='CarLoan' 
    GROUP BY D.CarID 
    ORDER BY D.CarID或
    SELECT MAX(R.Stage),D.CarID,D.RecordID
     FROM Repayinfo as R,CustomerBaseInfo as C,CustomerCarInfo as D 
     where R.RecordID=C.RecordID and C.Address like '%城区%' and     R.RepayKind='CarLoan' 
    GROUP BY D.CarID ,D.RecordID --加到group by 中
    ORDER BY D.CarID