Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
UPDATE question
Message
 
 
À
20/08/2009 06:58:11
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Divers
Thread ID:
01419198
Message ID:
01419200
Vues:
61
Agnes,

Try
UPDATE Test SET n1 = tm.n1m ;
	FROM Test JOIN ( ;
		SELECT t1.m1, t1.m2, MAX(t1.n1 * t2.f1) AS n1m ;
			FROM Test t1 JOIN Test2 t2 ON t2.Mx = t1.M1 OR t2.Mx = t1.M2 ;
			GROUP BY 1,2 ;
		) tm ON tm.m1 = Test.m1 AND tm.m2 = Test.m2	

* or

UPDATE Test SET n1 = Test.n1 * tm.f1m ;
	FROM Test JOIN ( ;
		SELECT t1.m1, t1.m2, MAX(t2.f1) AS f1m ;
			FROM Test t1 JOIN Test2 t2 ON t2.Mx = t1.M1 OR t2.Mx = t1.M2 ;
			GROUP BY 1,2 ;
		) tm ON tm.m1 = Test.m1 AND tm.m2 = Test.m2	
>
>again, I have a SQL Problem. This time it's an UPDATE:
>
>given
>
>CREATE CURSOR Test(M1 c(1), M2 c(1),n1 I)
>INSERT INTO Test Values('A','A',1.1)
>INSERT INTO Test Values('A','B',1.2)
>INSERT INTO Test Values('B','B',1.3)
>INSERT INTO Test Values('A','C',1.4)
>INSERT INTO Test Values('C','B',1.5)
>INSERT INTO Test Values('C','A',1.6)
>
>
>CREATE CURSOR Test2(Mx c(1),F1 I)
>INSERT INTO Test2 Values('A',1)
>INSERT INTO Test2 Values('B',4)
>INSERT INTO Test2 Values('C',2)
>
>
>I like to update Test.n1 with itself*Test2.F1,
>
>Now the problem. F1 is related via Mx to M1 and M2. if M1 !== M2 it should use the higher value of F1
>Example
>
>INSERT INTO Test Values('A','A',1.1) && -> n1:= 1.1  : F1(A)=F1(A)=1
>INSERT INTO Test Values('A','B',1.2) && -> n1:= 4.2  : F1(A)<F1(B); F1(B)=4
>INSERT INTO Test Values('C','B',1.5) && -> n1:= 6.0  : F1(C)<F1(B); F1(B)=4
>INSERT INTO Test Values('C','A',1.6) && -> n1:= 3.2  : F1(C)>F1(>); F1(C)=2
>
>
>any idea how to code this in one UPDATE statement?
>
>TIA
>Agnes
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform