Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A complex query
Message
 
 
To
25/11/2016 09:03:23
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 7
Network:
Windows XP
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01643947
Message ID:
01643979
Views:
51
>Dear Experts
>
>I have these codes
>
>
>CREATE CURSOR table1 (codes c(7),names c(10),amount n(4))
>INSERT INTO table1 VALUES ('1','',0)
>INSERT INTO table1 VALUES ('11','',0)
>INSERT INTO table1 VALUES ('1101','',0)
>INSERT INTO table1 VALUES ('1101001','',200)
>INSERT INTO table1 VALUES ('1101002','',600)
>INSERT INTO table1 VALUES ('1101005','',700)
>INSERT INTO table1 VALUES ('1102','',0)
>INSERT INTO table1 VALUES ('1102001','',100)
>INSERT INTO table1 VALUES ('1102003','',400)
>INSERT INTO table1 VALUES ('12','',0)
>INSERT INTO table1 VALUES ('1201','',0)
>INSERT INTO table1 VALUES ('1201001','',800)
>INSERT INTO table1 VALUES ('1201003','',300)
>
>
>
>I need result shown in image
>
>Please

In Visual FoxPro you would need to run the statement 3 times to get the result you want. Here is the first iteration:
SELECT T.Codes, X.TotalAmount ;
from Table1 T ; 
inner join (select SUM(Amount) as TotalAmount, LEFT(codes, 4) as FirstFour FROM Table1 GROUP BY 2) X ON T.Codes = X.FirstFour ;
where T.Amount = 0
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform