Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using count() in SQL Select
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00872467
Message ID:
00872476
Views:
24
Sergey,

Your approach will count total number of A orders and B orders. But I want to count number of UNIQUE orders. In example below George had 2 unique B orders yet he had 3 total B orders.

Thank you.

>Dmitry,
>
>
SELECT EMPLOYEE, ;
>          SUM( IIF(type="A",1,0)) AS cnt_a, ;
>          SUM( IIF(type="B",1,0)) AS cnt_b ;
>FROM mytable ;
>GROUP BY 1
>
>
>>I need help, please, in determining how to do the following (simplified):
>>
>>Table:
>>
>>
>>TYPE	ORDER_NO	EMPLOYEE
>>A	1         JOHN
>>B	2         PAUL
>>B	1         GEORGE
>>B	4         PAUL
>>A	1         GEORGE
>>B	2         GEORGE
>>B         2         GEORGE
>>
>>
>>I want summarize the above table (using SQL Select) into the following cursor:
>>
>>
>>EMPLOYEE     NUMBER OF A ORDERS    NUMBER OF B ORDERS
>>JOHN         1
>>PAUL         0                     2
>>GEORGE       1                     2
>>
>>
>>When there was no TYPE field, it was easy using:
>>count( distinct( ORDER_NO ) ) as NUM_ORDS group by EMPLOYEE
>>
>>But with introduction of TYPE I am lost.
>>
>>TIA.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform