0

I have a table t with columns foo and bar:

foo bar
a   x
a   y
b   z

I want to write something like

select foo, count(*) as num, SOMETHING(bar) from t group by foo;

and get

foo num bar
a   2   x    <--- or y, I don't care
b   1   z

I.e., SOMETHING should select an arbitrary value that appeared in a group (first, last, random - I don't care).

Is there a way to do it in sqlite3?

sds
  • 58,617
  • 29
  • 161
  • 278

1 Answers1

0

If you truly don't care, consider using MIN(bar) or MAX(bar). If you want it to be different each time, you'll need to number each value randomly and select the lowest corresponding value. This answer should help you if you choose that route.

Mr. Llama
  • 20,202
  • 2
  • 62
  • 115