1
I’m using this query: I would like to know how to count these fields that have no records. Here returns 0. But I have some null records. What I do?
SELECT DataFim, COUNT(DataFim) AS QTD FROM AtivacaoGuincho
GROUP BY DataFim
HAVING DataFim is null
1
I’m using this query: I would like to know how to count these fields that have no records. Here returns 0. But I have some null records. What I do?
SELECT DataFim, COUNT(DataFim) AS QTD FROM AtivacaoGuincho
GROUP BY DataFim
HAVING DataFim is null
8
Thus:
SELECT COUNT(*) AS QTD FROM AtivacaoGuincho
WHERE DataFim is null
Since Marlon brought up the subject of line accounting I can improve on a little more that answer and get into a subject that is almost a curiosity.
Count is basically used in this way above. I request that you count all lines WHERE THE END IS NULL.
But I could do so:
SELECT COUNT(*) AS TOTAL, COUNT(DATAFIM) AS DTFIM FROM AtivacaoGuincho
And it would have something like this: I have 1884 rows in the table and 50 rows where DATAFIM is null.
And of course, I could have as many Counts as I wanted in my select.
this returns me 2. It is correct
6
Missing the Where clause correctly..
SELECT COUNT(DataFim) AS QTD
FROM AtivacaoGuincho
WHERE DataFim is null
EDIT:
Sorry for the mistake of Ctrl+c/Ctrl+v, the correct is:
SELECT COUNT(*) AS QTD
FROM AtivacaoGuincho
WHERE DataFim is null
And for those who don’t know the difference between Count(*) and Count(coluna) is that:
Count(*) accounts for all lines without exceptions.Count(coluna) accounts for values of coluna who are not null
(null)this touches me 0
@Aline, I edited the answer with information that may be valuable to you :)
Oops, thank you, boy.
Awwwwwwwwwwwwwwwwwwwww got it
Now I know why I was returning 0...
Browser other questions tagged sql sql-server
You are not signed in. Login or sign up in order to post.
If you can, try
SELECT COUNT(*) - COUNT(DataFim) AS qtdand tell me if it works.– Bacco