Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL / GROUP BY (Join)
Message
 
 
To
26/09/2003 14:48:18
John Vlahos
V I Software Solutions Design
Mississauga, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00832747
Message ID:
00832795
Views:
16
Yes, In this case you can because you've fixed # of machines. Otherwise you'll have to use crosstab (see for example FastXtab File #9944).
SELECT ;
		SUM( IIF(LINE.ID="101", ROLLS.nWeight_Roll,0)) AS nAccepted_101, ;
		SUM( IIF(LINE.ID="102", ROLLS.nWeight_Roll,0)) AS nAccepted_102, ;
		...
		SUM( IIF(LINE.ID="111", ROLLS.nWeight_Roll,0)) AS nAccepted_111, ;
	FROM LINE ;
	LEFT JOIN ROLLS ;
	ON LINE.ID=ROLLS.clineid ;
	WHERE UPPER(ALLTRIM(CSTATUS))=="ACCEPTED" OR CSTATUS IS NULL ;
	INTO CURSOR tmpProduction
>Sergey:
>
>I have another issue:
>
>I would like to SUMmarize the weight of all rolls (a product) according to the machine it was produced on using a SQL statement, however the tricky part is that I would like to have the resultant counters (11 of them) in a cursor as fields across the table.
>
>I need it set up this way to facilitate in a report layout which must have the machine displayed accross.
>
>For example.
>SUM nAccepted  for Line "101" is 100 lbs
>SUM nAccepted  for Line "102" is 500 lbs
>.
>.
>.
>SUM(nAccepted) for Line "111" is 250 lbs
>
>I would like my result file to be setup as follow.
>
>Field:                   Value:
>======                  =========
>nAccepted_101           100
>nAccepted_102           500
>.
>.
>.
>nAccepted_111           250
>Is it possible with a SQL statement?
>
>All weights come from the same table ROLLS, and have the line number/code as part of the record.
>
>John
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform