Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to solve this SQL Select?
Message
 
 
To
27/02/2006 16:37:57
Cindy Winegarden
Duke University Medical Center
Durham, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01099608
Message ID:
01099677
Views:
11
>>I have the following SQL that sometimes gives me erroneous results:
>
>Try this:
>Create Cursor T1 (Pk C(1))
>Insert Into T1 Values ("A")
>Insert Into T1 Values ("B")
>
>Create Cursor T2 (Pk C(1), Fk C(1), Value I)
>Insert Into T2 Values ("X", "A", 100)
>Insert Into T2 Values ("Y", "A", 200)
>Insert Into T2 Values ("Z", "B", 500)
>
>Create Cursor T3 (Fk C(1), Value I)
>Insert Into T3 Values ("X", 1000)
>Insert Into T3 Values ("X", 2000)
>Insert Into T3 Values ("Y", 3000)
>Insert Into T3 Values ("Y", 4000)
>	
>Select ;
>	T1.Pk, ;
>	T2Result.SumT2value, ;
>	T3Result.SumT3Value ;
>From ;
>	T1 ;
>	Left Join ;
>		(Select T2a.Fk, Sum(T2a.Value) As SumT2Value From T2 T2a Group By 1) As T2Result ;
>			On T1.Pk = T2Result.Fk ;
>	Left Join ;
>		(Select T1a.Pk As Fk, Sum(T3.Value) As SumT3Value ;
>			From T1 T1a ;
>			Left Join T2 T2b On T1a.Pk = T2b.Fk ;
>			Left Join T3 On T2b.Pk = T3.Fk Group By 1) As T3Result ;
>		On T1.Pk = T3Result.Fk ;
>Group By 1
I will try your suggestion. Thank you so much.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform