大家好,我想在where/and子句中获取列的最后一个id。
这是我尝试过的:
SELECT i.documentnumber, i.documentseq, i.transactiondate, v.vancode, i.itemcode, i.qty, i.amount, i.reason, i.posted, i.dateposted, i.unitprice
FROM intrans AS i
JOIN intrans_vancode AS v ON i.locationcode = v.vancode
WHERE posted = 0
ORDER BY v.id DESC
但是我遇到了组函数错误/问题。
任何想法如何实现我想要的?感谢您的帮助。
如果您只是在寻找具有 Max id 的一条记录,为什么不使用变量:
Declare @MaxID int
Set @MaxId = ( Select Max(id) From intrans_vancode )
Select
i.documentnumber,
i.documentseq,
i.transactiondate,
v.vancode,
i.itemcode,
i.qty,
i.amount,
i.reason,
i.posted,
i.dateposted,
i.unitprice
FROM intrans AS i
Join intrans_vancode v On i.locationcode = v.vancode
WHERE i.posted = 0 -- you didn't specify a prefix so I don't which table this column belongs to
AND v.id = @MaxID