mysql - Performance issues and optimisation of a sql query with union and group by -


i have list of users want group criteria. simplified, grouped a, b, c, d, e.
e column can have value picked in list : 000, 071, 072, 2c, 2d, 2m, 3m, 3d.
can't regroup users have different value e, except 000, 072 , 071 can grouped (so e in not in group clause these users).
that, did first union looking (the real query contains several join instead of "users", adds complexity , useless question) :

select a, b, c, d, e users e not in ('071','072','000') group a,b,c,d,e union select a, b, c, d, group_concat(e) users e in ('071','072','000') group a,b,c,d 

until got job done. had add new column. column represents how user added our database. before, done automatically. can done manually, doing so, columns left empty, , e 1 of them because e table don't fill manual method. these users must regrouped '000', '071' , '072' (because default value when e null '000').

so imagined :

select a, b, c, d, e users e not in ('071','072','000') group a,b,c,d,e union select a, b, c, d, group_concat(e) e      (select a,b,c,d, '000' e  manual_users      union      select a, b, c, d, group_concat(e) e automatic users       e in ('071','072','000') ) 000 group a,b,c,d 

do think way make simpler? actual database query 150 lines long, i'm sure in other way


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -