János - 11 months ago 42

SQL Question

Looking for an aggregate method, or any smart approach that can result the following:

`- SELECT MIN_DISTANCE(set, b) FROM {a, b, c, d} set => b`

- SELECT MIN_DISTANCE(set, b) FROM {e, f, g} set => e or f or g

- SELECT MIN_DISTANCE(set, b) FROM {} set => no result

Answer Source

I think you just want a `case`

expression:

```
SELECT (case when MIN_DISTANCE(set, b) in ('a', 'b', 'c', 'd') then 'b'
when MIN_DISTANCE(set, b) in ('e', 'f', 'g') MIN_DISTANCE(set, b)
end)
```