Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL question
Message
 
 
À
06/08/2009 10:09:11
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:
01416401
Message ID:
01416482
Vues:
56
>>>>Unfortunately, this would not give us only error cases - I just thought of the same SQL. You don't need to join here. This would give all C3 cases even when a/b combination is the same - I don't see a simple way to separate them - need to think.
>>>
>>>Yes, and start reading the question first
>>
>>I believe we wanted to get all records where we have discrepancy. BTW, I figured this out while driving.
>>
>>select T.* from myTable T INNER JOIN (select a,b,c from myTable group by c, a, b) X on T.c= X.c and (T.a<>X.a OR T.b <>X.b)
>
>Same defect as message#1416403
>
>try with this
>
>	
>		create cursor Schnaps ;
>	(	c1	c(1), ;
>		c2	c(1),; 
>		c3	c(1) ;
>	)
>	
>	insert into Schnaps values ('A', 'a', '1')
>	insert into Schnaps values ('A', 'b', '2')
>	insert into Schnaps values ('A', 'b', '3')
>	insert into Schnaps values ('B', 'c', '4')
>	insert into Schnaps values ('B', 'd', '4')
>	insert into Schnaps values ('B', 'e', '4') && added
>	insert into Schnaps values ('B', 'f', '4') && added
>	insert into Schnaps values ('A', 'b', '3')
>
Unfortunately, the problem is too complex - I spent ~20+ minutes and could not solve it - need real concentration - may try tonight at home.
	create cursor Schnaps ;
	(	c1	c(1), ;
		c2	c(1),; 
		c3	c(1) ;
	)
	
	insert into Schnaps values ('A', 'a', '1')
	insert into Schnaps values ('A', 'b', '2')
	insert into Schnaps values ('A', 'b', '3')
	insert into Schnaps values ('B', 'c', '4')
	insert into Schnaps values ('B', 'c', '4')
	insert into Schnaps values ('B', 'd', '4')
	insert into Schnaps values ('B', 'e', '4') && added
	insert into Schnaps values ('B', 'e', '4') && added
	insert into Schnaps values ('B', 'f', '4') && added
	insert into Schnaps values ('A', 'b', '3')
	
	select T.* from Schnaps T INNER JOIN ;
	(SELECT c3, MIN(c1) as c1_min,MAX(c1) as c1_max, ;
	MIN(c2) as c2_min, MAX(c2) as c2_max FROM Schnaps X group by 1 ;
	HAVING COUNT(distinct(c1+c2)) > 1) X ON T.c3= X.c3
I only want to select the non-matching values, such as b,d,4 and b,f,4.

BTW, in SQL Server 2005 and up this problem can be easily solved with row_number() function.
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform