Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can Count(), CASE(), and Distrinct be combined?
Message
 
 
À
28/01/2019 15:41:43
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01665760
Message ID:
01665766
Vues:
56
>>Hi,
>>
>>I am trying to count unique values in the field (using SQL Select) if the value is greater than 0
>>
>>So, here is syntax I use (simplified) (which generates an error):
>>
>>select count( case when mytable.myfield = 0 then 0 else distinct( mytable.myfield ) end ) as TotCount
>>
>>
>>What is wrong in the above syntax?
>>
>>TIA
>
>I don't understand the reason for using Distinct, can you explain what you need it for? Distinct is used to avoid doubles when you select many records, but you only want the count. This makes me confused.
>
>And you don't need the Case() to eliminate the fields holding 0, since a total on fields holding 0 will be 0 anyway.
>
>May I suggest that you show the "real" select statement, and not the "simplified" one?

I see where the confusion come in. I need to do away with COUNT().

The entire SQL select will confuse you even more. But here is the description. I am selecting all orders. Some orders have the value of 0. And I want to show in the report how many orders, of each order number - other than 0 - are in the report.
If I simply use distinct( mytable.myfield ) as TotCount then the TotCount has one extra value (for the orders that have the value of 0).

And in this case the district has nothing to do with the case of avoiding doubles.

Thank you.

UPDATE. I do want to include COUNT(). Please see my reply to myself.
"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
Répondre
Fil
Voir

Click here to load this message in the networking platform