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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -