Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Anders Altberg
  Where is Anders Altberg?
 Uppsala
 Sweden
 Anders Altberg
 To: Ryan Lashway
  Where is Ryan Lashway?
 Warrensburg
 New York - United States
 Ryan Lashway
 Tags
Subject: RE: Combind Records
Thread ID: 202104 Message ID: 202323 # Views: 23 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Thursday, November 06, 2008 10:39:35 PM         
   


> >
> >
> >
> > * Select TOQtemp
> > * Goto Top
> > * Those two lines are superfluous. A SELECT SQL query opens the table in
> > * the FROM * clause and reads it straight from the harddisk.
> >
> >
 
> > Select field1, field2,P_ID,;
> >  Cast(Sum(field4) As N(12,2)) As item1,;
> >  CAST(Sum(field5) As N(12,2)) As item2,;
> >  CAST(Sum(field6) As N(12,2)) As Total;
> >  FROM TOQtemp ; 
> >  Group By P_ID, field1, field2
> >  Browse
> > 
> > Note 
> > * Select field1, field2, P_ID
> > * Group By P_ID, field1, field2 
> > * Same columns in SELECT and GROUP BY lists. 
> > * The rest of the columns are all SUM() aggregations.
> > * You cannot SELECT nor GROUP BY a column that is aggregated in a SUM() 
> > 

> > -Anders
>
> Works great, but one question, how can I show fields I do not want to group by ? Main part of this is I have mulipal accounts with different account # but the same P_ID so I need one record for the reports that shows total for all those records ?
>
> Ryan J. Lashway
> http://www.lashtech.com

Are yoy saying that you want two levels of summing in a single query: A sum for account numbers group, and a sum for each p_id group.
That's fairly easy in a Report based on a query cursor with ORDER BY p_id, account_no
You can simply run two separate queries with GROUP BY account_no in one and GROUP BY p_id in the other
If you could post some minimal data set that shows an example of this + the result as you want to see it based on those records I will try and solve the problem.
The best way to show data so that everybody here can have a go at it is with
CREATE CURSOR xx (,,,,) 
INSERT INTO xx VALUES ( ,,,, ) 
INSERT INTO xx VALUES ( ,,,, ) 
INSERT INTO xx VALUES ( ,,,, ) 


Expected result:

col1, col2, col3
.. ... ....
.. ... ....


-Anders



COMPLETE THREAD
Combind Records Posted by Ryan Lashway @ 11/5/2008 11:34:59 PM
RE: Combind Records Posted by Jun Tangunan @ 11/5/2008 11:51:12 PM
RE: Combind Records Posted by Cetin Basoz @ 11/5/2008 11:52:28 PM
RE: Combind Records Posted by Ryan Lashway @ 11/6/2008 12:40:27 AM
RE: Combind Records Posted by Jun Tangunan @ 11/6/2008 1:14:45 AM
RE: Combind Records Posted by Ryan Lashway @ 11/6/2008 2:30:00 PM
RE: Combind Records Posted by Anders Altberg @ 11/6/2008 2:53:08 PM
RE: Combind Records Posted by Ryan Lashway @ 11/6/2008 3:33:33 PM
RE: Combind Records Posted by tushar @ 11/6/2008 4:05:25 PM
RE: Combind Records Posted by Anders Altberg @ 11/6/2008 5:09:32 PM
RE: Combind Records Posted by Ryan Lashway @ 11/6/2008 8:33:13 PM
RE: Combind Records Posted by Anders Altberg @ 11/6/2008 10:39:35 PM
RE: Combind Records Posted by Cetin Basoz @ 11/6/2008 4:06:22 PM
RE: Combind Records Posted by Mike Yearwood @ 11/6/2008 3:21:48 PM
RE: Combind Records Posted by Ryan Lashway @ 11/6/2008 9:36:42 PM