Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL - Select & SUM
Message
 
 
To
31/07/2003 08:05:57
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00815321
Message ID:
00815327
Views:
8
This message has been marked as the solution to the initial question of the thread.
Assuming that you've exactly 4 plans.
SEKLECT Name, ;
  SUM(IIF(planid=1, noshares, 0)) AS Plan1, ;
  SUM(IIF(planid=2, noshares, 0)) AS Plan2, ;
  SUM(IIF(planid=3, noshares, 0)) AS Plan3, ;
  SUM(IIF(planid=4, noshares, 0)) AS Plan4, ;
 FROM mytable ;
 GROUP BY name
If you have variable namber of plans, than you should use crosstab generator, like FastXtab File #9944

>I have a table as follows:
>
>
>NAME       PLANID      NOSHARES
>Russell      1            50
>Russell      4            45
>Mark         3            50
>Mark         2           100
>John         3            30
>Russell      1            70
>Mark         1            35
>Mark         2            20
>
>
>What I would like produced from an SQL Statement is :
>
>
>NAME     PLANID 1    PLANID 2   PLANID 3    PLANID 4
>Russell     120          0         0            45
>Mark         35         120       50             0
>John          0          0        30             0
>
>
>Is this possible? If so, How?
>
>Thanks in advance for your help,
>Russell
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform