group by - Grouping an outcome in MySQL -
i'm doing simple mysql query , use group give me set of results of locations rather having run query uncommenting various lines on each occasion. i'm confused whether or not use group in select or clause.
select count(*) users u -- northern ireland u.postcode_area in ('bt') -- wales -- u.postcode_area in ('cf','ch','gl') -- scotland -- u.postcode_area in ('ab','dd','dg','eh','fk')
so outcome i'd see
- northern ireland | 25678
- wales | 34543
- scotland | 4567
you below:
select (case when u.postcode_area in ('bt') 'northern ireland' when u.postcode_area in ('cf','ch','gl') 'wales' when u.postcode_area in ('ab','dd','dg','eh','fk') 'scotland' else 'other') country, count(*) users u group country
Comments
Post a Comment