以下是引用hgfeng1984在2010-9-3 21:33:29的发言:
SELECT DISTINCT A.* FROM #TEMP A
INNER JOIN
(SELECT CUSTNO,ITEM,MAX(SALEDATE) AS SALEDATE FROM #TEMP GROUP BY CUSTNO,ITEM) B
ON A.CUSTNO=B.CUSTNO AND A.ITEM=B.ITEM AND A.SALEDATE=B.SALEDATE
Hi hgfeng1984:
SYNTAX ERROR
受你的MAX()启发虽然我无法实现一行代码,但比起用DO WHILE ....还是强了不少,谢谢!
为了使所有看帖的人都受益,特附送artran98.dbf , arytrn98.dbf 有兴趣的朋友可以自已动手试试,最好可以实现一行代码,大家共同学习
程序代码:
CLOSE ALL
USE C:\temp\artran98.dbf IN 0 SHARED
USE C:\temp\arytrn98.dbf IN 0 SHARED
** Single Customer MAX(invdte) history sales
SELECT * FROM artran98;
INTO CURSOR a_tran;
WHERE TRAN(custno) = '65RTON';
UNION;
SELECT * FROM arytrn98;
WHERE tran(custno) = '65RTON'
** Remove same item duplicates record ORDER BY Invdte
SELECT MAX(INVDTE) AS Invoice_Date,Invno,Custno,Item,Descrip,Cost,Price Qtyord,Qtyshp;
INTO CURSOR answer;
FROM a_tran GROUP BY item;
ORDER BY item
SELECT answer
BROWSE
** All Customer MAX(invdte) history sales
SELECT * FROM artran98;
INTO CURSOR a_tran2;
UNION;
SELECT * FROM arytrn98
** Remove same item duplicates record ORDER BY Invdte
SELECT MAX(INVDTE) AS Invoice_Date,Invno,Custno,Item,Descrip,Cost,Price Qtyord,Qtyshp;
INTO CURSOR answer2;
FROM a_tran2 GROUP BY custno,item;
ORDER BY custno,item
SELECT answer2
BROWSE
[
本帖最后由 twy628659 于 2010-9-4 11:22 编辑 ]