I have a table that has 5 "optional" fields. I'd like to find out how many rows have all 5 null, how many have 1 field non-null, etc.

I've tried a couple of things, like:

```
select 
 count(*),
 ( (if field1 is null then 1 else 0) +
   (if field2 is null then 1 else 0) +
 etc.

```

but of course that doesn't work.

Ideally, I'm looking for output that's something like

```
Nulls   Cnt
0        200
1        345
...
5        40

```

Is there an elegant solution?