Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set relationship
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01593576
Message ID:
01593628
Views:
50
>>You can get your sums from each table into cursors and then join all these cursors together for your final result to get total sum.
>
>Naomi, I have the following questions about your SQL query and want to thank you, Steve
>
>select  ;
>NVL(T1.RatingSum,0) + NVL(T2.RatingSum) as TotalRating, ;
>NVL(T1.yymmddhh, T2.yymmddhh)  AS yyMMddhh	;
>FROM  ;
>(  ;
>select ;
>sum(mRating) 	as RatingSum,	;
>LEFT(mDate,10)  as yyMMddhh	        ;
>from Table1 	                                        ;
>GROUP BY 2						;  && what does Group by 2 mean?
>) 	 ;
>T1	 ;
>FULL JOIN  ;
>(	;
>select  ;
>sum(mRating) 	as RatingSum, ;
>LEFT(mDate,10)  as yyMMddhh  	;
>from Table2 	;
>GROUP BY 2						;  && again?
>) 	;
>T2	;
>ON T1.yymmddhh = T2.yymmddhh		&& use ON instead of WHERE, I guess
>
Group by 2 means group by the second column (in our case it's computed column without the minutes part). In VFP we can not use computed column in the GROUP BY expression (as in SQL Server), so we have to use the ordinal number of the column.

The query above sums first by hour in Table1 and Table2 and then uses a FULL JOIN (in case there may be rows in one table and not in another) between these two derived tables to get the total sum.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform