Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Data grouping with the reference of last transaction
Message
 
 
To
30/03/2003 09:01:53
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00771821
Message ID:
00771832
Views:
19
This message has been marked as the solution to the initial question of the thread.
Hi Yashodhan,

In addition your query wouldn't even run in VFP8. You can get result by spliting your query in two steps. The first query will get key fileds (cust_no, stock_no), MAX date and SUM of net. The second query will join result of the first one back to the original table to get the rest of fields.
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 

>Hi everybody.
>I want to generate a file, which gives me the following data for each customer and stock number –
>Customer number, stock number, total sell, reference of the last transaction like document type, date, document number and unit price
>I tried following SQL -
>
>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?
>
>Thanks in advance.
>Yashodhan.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform