Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Group by summary
Message
From
06/08/2007 12:43:56
 
 
To
06/08/2007 04:45:55
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01246096
Message ID:
01246179
Views:
24
>Dear Experts
>
>Table1 has four fields as
>
>code n(4)
>name n(4)
>amount n(5)
>type c(1)
>
>Data in fields is as
>
>code----name----amount--type
>1101----Eric-----100-----B
>1202----Bill-------200-----B
>1506----Boris----600-----A
>1608----Cetin----900-----A
>1709----Jack-----800-----A
>2101----Ali--------900-----B
>2202----Tame---100-----A
>2608----Zahi-----100-----A
>
>I need following output based on two conditions
>
>Group + type
>Every group is based on First digit of code
>Type is based on A and B
>
>Codes between 1100 to 1900 is Group 1
>Codes between 2000 to 2900 is Group 2 and so on
>
>This should be Final Output
>
>code----name----amount--type
>2--------2-------300------B && total of group 1 with type=B
>3--------3-------1700-----A && total of group 1 with type=A
>1--------1-------900------B && total of group 2 with type=B
>2--------2-------200------A && total of group 2 with type=A
>
>
>Please help

Perhaps.......
SELECT INT(code/1000) cc,count(code/1000),count(dist name),sum(amt),type FROM gloop;
group BY cc,type
I made an assumption you want a count of unique names (otherwise the number of names is the number of records

You also have (I'm pretty sure) an error in the amount for group 1 Type A. It should be 2300 for Boris, Cetin, and Jack.

I also made an assumption (INT(code/1000)) about the rule for Group1,2, etc. based upon your "and so on" comment.

You don't have the actual group number in your final results. I couldn't quite figure out a way to do that in one step, but the following might also work
SELECT INT(code/1000) cc,* FROM gloop INTO CURSOR xxx

SELECT count(code/1000),count(dist name),sum(amt),type FROM xxx;
group BY cc,type
Previous
Reply
Map
View

Click here to load this message in the networking platform