我有以下表选择的一组是最后一个他们自己的类型
LogCheque(LogChequeID,ChequeID,日期,HolderID)
每行显示了哪些检查(ChequeID)被转移记录谁(HolderID)在哪个日期。
我想选择LogCheques的名单,但每次检查只出现一次,显示
例如数据
LogChequeID ChequeID Date HolderID
1 1012 2013-01-10 200
2 1526 2013-01-12 125
3 1012 2013-01-19 413
4 1526 2013-02-11 912
5 1526 2013-02-17 800
最后转移我的期望输出将
LogChequeID ChequeID Date HolderID
3 1012 2013-01-19 413
5 1526 2013-02-17 800
我有试过
select lch.ChequeID, lch.DateFa, lch.ChequeID
from LCheque lch
group by lch.ChequeID, lch.DateFa, lch.LChequeID
having lch.LChequeID = (select MAX(LChequeID) where ChequeID = lch.ChequeID)
但是我t返回每一行。
任何帮助将大大有助于和赞赏张开双臂:)在此先感谢。
@Mahdi Tahsildari这很有趣?!?这个答案错了。 Eror:列'dbo.test20.HolderID'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。 – 2013-03-03 09:04:33