Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL - How to get the desired result?
Message
From
24/01/2007 10:04:22
 
 
To
24/01/2007 10:01:11
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01188662
Message ID:
01188667
Views:
21
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform