Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Totaling records in an sql
Message
From
13/08/2003 12:28:18
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
13/08/2003 12:24:30
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00819829
Message ID:
00819833
Views:
8
This message has been marked as the solution to the initial question of the thread.
>Hello everybody.
>
>i know i've seen the solution here at UT before, but can't remember where it was (working in Vfp6 sp 5).
>
>I have a header sales order table (comast) and a detail sales order table (codet) where there are multible (or one) records for each sales order. what i need is a sql command which totals those records, giving me one record for each customer and for a specific month (or month range).
>
>i have currently:
>SELECT ;
>		b.custid, ;
>		a.usell*a.qtyord as usell, ;
>		b.reqdate ;
>	FROM "codet" a, "comast" b ;
>	WHERE ;
>		inlist(b.custid, padr("32312", 8)) .and. ;
>		a.Custid = b.custid .and. ;
>		BETWEEN(b.reqdate, date(), DATE()+(31)) ;
>	ORDER BY b.reqdate ;
>	INTO CURSOR cur_Temp
>
Use GROUP BY, for instance:
select Customer, Month, sum(usell*qtyord) as Amount;
  from Cur_Temp;
  into Cur_Temp2;
  group by Customer, Month
>this gives me a table with all detail records for the customer (ID) "32312" and the due date (reqdate) between today and 31 days from now.
>
>I need to end up with one record per customer + per month. Those records need to have a total dollar amount (a.usell*a.qtyord) for this time frame + for this customer. as you can see i used 'InList()' to select the customer, as i might whant to do this with a range of customers.
>
>i am not that familier when it comes to complex sql like this one.
>i was thinking of using the group clause somehow, but was unsuccessfull with this.
>
>any help is as alway greatly appreaciated.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform