Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What parameter to use fo this COUNT()
Message
 
To
08/10/2007 12:06:46
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01259476
Message ID:
01259480
Views:
21
>Can someone suggest the right parameter to pass to COUNT() function of SQL Select to accomplish the following:
>
>Table fields
>ID, C
>WEEK, N
>HRS, N
>
>
>select week, id, sum(hrs) as week_hrs, count(???) as week_cnt from
>mytable group by week, id
>
>
>I want the week_cnt in the above SQL Select to count how many records found for a given WEEK and given ID. I tried using count(*) but it gives me total of all records.
>
>I would appreciate any suggestions.

No way:
CREATE CURSOR crsTest (ID C(10), Week I, Hrs N(10,2))
INSERT INTO crsTest VALUES ([ID1], 1, 12)
INSERT INTO crsTest VALUES ([ID1], 1, 12)
INSERT INTO crsTest VALUES ([ID1], 1, 12)
INSERT INTO crsTest VALUES ([ID1], 1, 12)
INSERT INTO crsTest VALUES ([ID1], 1, 12)
INSERT INTO crsTest VALUES ([ID1], 1, 12)
INSERT INTO crsTest VALUES ([ID1], 1, 12)
INSERT INTO crsTest VALUES ([ID1], 1, 12)

INSERT INTO crsTest VALUES ([ID1], 2, 12)
INSERT INTO crsTest VALUES ([ID1], 2, 12)
INSERT INTO crsTest VALUES ([ID1], 2, 12)


INSERT INTO crsTest VALUES ([ID1], 3, 12)

INSERT INTO crsTest VALUES ([ID2], 1, 12)
INSERT INTO crsTest VALUES ([ID2], 1, 12)
INSERT INTO crsTest VALUES ([ID2], 1, 12)

INSERT INTO crsTest VALUES ([ID2], 2, 12)
INSERT INTO crsTest VALUES ([ID2], 2, 12)
INSERT INTO crsTest VALUES ([ID2], 2, 12)


INSERT INTO crsTest VALUES ([ID2], 4, 12)
select week, id, sum(hrs) as week_hrs, count(*) as week_cnt from crsTest group by week, id
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform