SELECT *
FROM CProduct T
WHERE (CustomID = 398) AND (CTID =
(SELECT MAX(CTID)
FROM CProduct
WHERE productno = T.productno))
ORDER BY ProductNOCTID是自动编号ProductNO是产品编号取出不重复记录的值,以上语句没有取出来,如果CustomID=471就可以取出,不知是哪里问题
FROM CProduct T
WHERE (CustomID = 398) AND (CTID =
(SELECT MAX(CTID)
FROM CProduct
WHERE productno = T.productno))
ORDER BY ProductNOCTID是自动编号ProductNO是产品编号取出不重复记录的值,以上语句没有取出来,如果CustomID=471就可以取出,不知是哪里问题
FROM CProduct T
WHERE (CustomID = 398) AND (CTID =
(SELECT MAX(CTID)
FROM CProduct
WHERE productno = T.productno and CustomID = 398))
ORDER BY ProductNO
--lz的没看出来问题,下面的试试先
SELECT * FROM CProduct T
WHERE CustomID = 398 AND
not exists(select 1 from CProduct where productno = T.productno and CTID>T.CTID)
ORDER BY ProductNO
SELECT * FROM CProduct T
WHERE CustomID = 398 AND not exists(
select 1 from CProduct where productno = T.productno and CTID>T.CTID)
*
FROM
CProduct T
WHERE
CustomID = 398
AND
not exists(select 1 from CProduct where productno = T.productno and CTID>T.CTID)
加上AND CustomID=t.CustomID
SELECT *
FROM CProduct T
WHERE (CustomID = 398) AND (CTID =
(SELECT MAX(CTID)
FROM CProduct
WHERE productno = T.productno AND CustomID=t.CustomID))
ORDER BY ProductNO
FROM CProduct T
WHERE CustomID = 398
having CTID = MAX(CTID)为什么要用子查询呢?说取不出来是因为MAX的原因吧。
MAX是在where后面执行。
也就是 SQL会先找出CustomID = 398 的所有数据。然后在取这些数据中的 MAX(CTID) 半年没用SQL的人