SQL how to make me return the number of negative intervals (INTERVAL of date)

Asked

Viewed 84 times

1

dif_active date_fimdegus is a range of the difference between 2 date fields, which return me, for example, -1 day.

I wonder how I can make a Count of all records that are negative in this column.

  • Which DBMS is using?

  • Could you explain your first line better? dif_dataativaca_fimdegus would be a Function that returns the difference between dates?

1 answer

0

Data is missing but it 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

After @ramaral observation, I believe this is it , but I repeat it was unclear 9at least to me) the doubt.

  • Review your answer because what AP wants is "a Count of all records that are negative in this column"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.