sql - MySQL how to group into subgroups of rows -


i have db: (note id unique)

enter image description here

i trying this:

enter image description here

what efficient sql query achieve this?

select      distinct     foo2.group_id group_id,     if(foo1.group_id = foo2.group_id, foo1.id, null) id,     if(foo1.group_id = foo2.group_id, foo1.some_attr, null) some_attr  mytable foo1     join     (select distinct group_id mytable) foo2             order group_id, id 

Comments

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -