Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can Count(), CASE(), and Distrinct be combined?
Message
 
 
To
28/01/2019 15:56:04
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01665760
Message ID:
01665769
Views:
41
>>>>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?
>>>
>>>I am not aware of that syntax in SQL. It might work but I've never used it. With what I know, I would use this:
>>>
>>>
SELECT DISTINCT mytable.myfield FROM mytable WHERE mytable.myField != 0 INTO CURSOR tmp1
>>>? _TALLY  && Display the distinct count
>>
>>First, thank you for your message. You see, my entire SQL Select need to include the records where mytable.myfield is 0. But I only want to count those that are not 0. Therefore, I cannot use your syntax.
>
>
SELECT *, SUM(IIF(myfield = 0, 0, 1)) as TotCount...
Please see my reply to Tore. I am not trying to COUNT(). I know in the example of this message I wrongly used COUNT(). I am trying to find the number of DISTINCT values; If the value is greater than 0.
"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
Reply
Map
View

Click here to load this message in the networking platform