SELECT cust_no, stock_no, ; MAX(doc_date) AS maxdoc_date, SUM(net) AS tot_net ; FROM t_invch ; GROUP BY cust_no, stock_no ; INTO CURSOR crsGroup SELECT gr.cust_no, gr.stock_no, ; inv.doc_date, inv.doc_type, inv.doc_no, ; gr.tot_net, (inv.net / inv.qty) AS unit_rate ; FROM crsGroup gr ; JOIN t_invch inv ; ON inv.cust_no = gr.cust_no ; inv.stock_no = gr.stock_no ; inv.doc_date = gr.maxdoc_date ; INTO CURSOR inv_cur
>SELECT CUST_NO, STOCK_NO, MAX(DOC_DATE), DOC_TYPE, DOC_NO, ; > (NET / QTY) AS UNIT_RATE, SUM(NET) AS TOT_NET ; >FROM t_invch ; >INTO CURSOR inv_cur ; >GROUP BY CUST_NO, STOCK_NO >>With this, I got the total sell and last transaction date correctly. But other details like DOC_TYPE, DOC_DATE etc. of the last record, not of the last transaction date. What should be the proper SQL for this query?