I have a query which returns the most common value for each gid. The code is follows:

```
select distinct on(gid) gid, max_height
from (
select gid, max_height, count(id) as freq
from my_table
group by 1, 2
) s
order by gid, freq desc, max_height desc

```

For the following sample data:

```
gid id  max_height
3   1   19.3
3   2   19.3
3   3   20.3
3   4   20.3
3   5   19.3
3   6   19.3
3   7   21.4
3   8   21.4
3   9   21.4
3   10  21.4
3   11  21.4
3   12  21.4
22  1   23.1
22  2   23.1
22  3   23.1
22  4   23.1
22  5   23.1
22  6   23.1
22  7   22.1
22  8   22.1
22  9   22.1
22  10  22.1
22  11  22.1
22  12  22.1
29  1   24.1
29  2   22.2
29  3   25.3
29  4   15.4
29  5   17.2
29  6   18.9
29  7   2.5
29  8   3.5
29  9   25.1
29  10  27.1
29  11  5.5
29  12  6.5

```

Each gid is unique and it contains 12 values of ID and max\_height. I need to modify above code such that it should return 0.0 when there is no most common value (mode) for any gid. Based on this, the desired output could be:

```
gid    max_height
3      21.4
22     23.1
29     0.0

```

Can anyone provide some pointers to get my desired output?