Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL SELECT and COUNT - how?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00113907
Message ID:
00114489
Views:
13
>I have a table with 4 fields of interest: user_id, user_source, task_id, subTask_id. I would like to know things like how many users (user_id) from each source (user_source) used each task (task_id), and how many users (all sources) used each sub task (subTask_id). I do not want to count duplicates (the same user_id using the same subTask_id for example). The output should be a cursor showing each user_source, the subTask_id, and the number of users from that source who used this subTask_id. For example:
>
> Source_ID sub_ID num_Users
> 1 2 15
> 1 3 25
> 2 2 19
>
>and so on ...
>
>I know I can do this the hard way by using variables and incrementing counters, but how can I do this using SQL SELECT and COUNT?
>
>Mon

Here's the basic code, you can modify to meet your needs.

SELECT last,first, ;
COUNT(last) AS duplast ;
FROM cust ;
WHERE NOT EMPTY(last) ;
GROUP by 1,2 ;
ORDER BY 3 DESC ;
HAVING duplast > 1 ;
INTO CURSOR curDup

This is the code I use to look for Duplicate last names in my cust table and get a count to the number of duplicates. This should give you a starting point for your problem.

Hope this helps
Fred Lauckner

You know, it works on my computer. I don't know what your problem is.

.Net aint so bad.
Previous
Reply
Map
View

Click here to load this message in the networking platform