Skip to content
Advertisement

Count only if field is filled

I have a question about a SQL query I want to write. Suppose I have a column with the follow values in table: school with column: grades.

 SUI grades | Score
  2  9          2
  2  9          
  5  4          1
  5  4          1
  5  4
  6  1          1
  6  1          

Now I want an output where it groups the SUI that counts grades only if Score is filled. So my output will be:

SUI Count 
 2    1
 5    2
 6    1

Advertisement

Answer

If the values are just blank and NOT NULL you can use function <> ” It will only count those field that have values in them

SELECT SUI, Count(Grades)
FROM mytable 
WHERE Score <> ''
GROUP BY SUI
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement