-2
I have this query:
SELECT COUNT(*) FROM USER_IND_COLUMNS
WHERE TABLE_NAME = UPPER('TABLE')
AND COLUMN_NAME IN (UPPER('ANO'),UPPER('MES'),UPPER('DIA'),UPPER('HORA'))
GROUP BY INDEX_NAME HAVING COUNT(*) = 4;
As there are no records, it should return 0 but does not return anything, how to return 0 if there are no occurrences.
You are explicitly selecting only those that have
count
equal to 4, but you expect it to be 0 in the result? It would be like taking only the white stockings of the wardrobe and wondering that there is no red in the middle.– Woss
@Does Andersoncarloswoss have a more elegant way of doing this? I need to test an if in this result.
– Roknauta
First you need to describe exactly what you need to do. If you need results that have a value other than 4, simply remove such a condition. In fact, what’s the point of doing
UPPER('TABLE')
,UPPER('ANO')
, etc? All strings are uppercase, so why use the functionupper
? It should not be together with the value that is variable?– Woss
@But it’s not about elegance, it’s about coherence. It could "solve" with coalesce, but how do you want it to result in zero if you explicitly say you only want it when the count equals 4?
– Jéf Bueno