Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL - How to get the desired result?
Message
De
24/01/2007 10:04:22
 
 
À
24/01/2007 10:01:11
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01188662
Message ID:
01188667
Vues:
22
This message has been marked as the solution to the initial question of the thread.
>Hello to all,
>can somebody help me with VFP9 SQL from my Sourcetable to the Targettable ?
>
>
My Sourcetable
>--------+-------+-------+------+
>iID	|cArt	|cColor	|iUnits|
>--------+-------+-------+------+
>	|Cars	|red	|    10|
>	|Cars	|blue	|     5|
>	|Cars	|green	|     2|
>	|Jeeps	|red	|     3|
>	|Jeeps	|blue	|     1|
>	|Jeeps	|green	|     4|
>	|Vans	|red	|     2|
>	|Vans	|blue	|     0|
>	|Vans	|green	|     0|
>
>The Targettable: Target.dBF
>--------+-------+----------+----------+----------+
>iID	|cArt	|iRed_Units|iBlue_Unit|iGreen_Uni|
>--------+-------+----------+----------+----------+
>	|Cars	|        10|         5|       	2|
>	|Jeeps	|         3|	     1|	        4|
>	|Vans	|         2|	     0|	        0|
>
>SELECT iID, cArt, ;
>   SUM(IIF(cColor="red",  iUnits, 0)) AS iRed_Units, ;
>   SUM(IIF(cColor="blue", iUnits, 0)) AS iBlue_Unit, ;
>   SUM(IIF(cColor="green",iUnits, 0)) AS iGreen_Uni ;
>   GROUP BY cArt, 1
>   FROM (lcDPFE_TabSource) ;
>   INTO TABLE "Target"
>
>My SQL idea not work right. I think, GROUP BY reduced the Resultrecords, but IIF() add the records again.
>
>Many Thanks for youre help.

Take out iId, i.e. you should group by cArt only.
Edward Pikman
Independent Consultant
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform