mysql group by only displays one?
仅有的幸福
仅有的幸福 2017-07-04 13:43:42
0
3
1103

Assume user table

| id | name | group |
| 1 | evan | admin |
| 2| charlie | admin|
| 3 | kid | user |
| 4 | ward | user |
|5 | fy | user |
select * from user group by user.group
Why there are only 2 pieces of data selected, instead of dividing users whose group is admin into one group, and grouping users whose group is admin The users of user are divided into a group
How can mysql achieve the desired effect...
Currently the only thing I can think of is to take them all out, then traverse user.group as the key, and then re-obtain the group. Can the database directly achieve this?

仅有的幸福
仅有的幸福

reply all(3)
phpcn_u1582

How to group with mysql? Repeated

过去多啦不再A梦

mysql does not have it, just write one yourself, directly order by group to get the data, and then:
pseudo code

def map,arr, g
for x in list
    if x.group != g
      g = x.group
      arr.new
      map.put(g,arr)
   arr.add(x)

Collection operations in many languages ​​already include such functions, such as java8...

曾经蜡笔没有小新

This means dividing admin into one group and user into one group to get two pieces of data. I didn’t understand what the poster said

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template