SQL how do I get back the number of negative ranges (date INTERVAL)

1

dif_dataactivation_fimdegus is a range of the difference between 2 date fields, which I return, for example, -1 day.

I would like to know how I can make a count of all records that are negative in this column.

    
asked by anonymous 11.05.2015 / 16:13

1 answer

0

Data is missing but will be something like this

testing only negative values

select count(dif_dataativacao_fimdegus) soma
from tabela
where dif_dataativacao_fimdegus <= -1

or

Treating a column with only negative values

select count(case when dif_dataativacao_fimdegus <= -1 then
                dif_dataativacao_fimdegus else null end) soma_do_neg,
      count(dif_dataativacao_fimdegus) soma
from tabela

Post-observation of @ramaral, I believe this to be, but I repeat it was unclear, at least for me) the doubt.

    
11.05.2015 / 17:06