sql - How to get values grouped by name? -


i have table

id name  no 1  alex  12 2  alex  13 3  kale  14 4  kale  15 

how 'no' values grouped 'name', should return following

alex - 12,13 kale - 14,15 

if want avoid writing sql, can in django:

in [1]: my_app.models import mymodel  in [2]: result = {}  in [3]: o in mymodel.objects.only('name', 'no'):    ...:     result[o.name] = result.get(o.name, []) + [o.no]    ...:       in [4]: result out[4]: {u'alex': [12, 13], u'kale': [14, 15]} 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -