Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using count() in SQL Select
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00872467
Message ID:
00872476
Vues:
25
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform