MySQL names resolution order in query -


i switched in app sqlite mysql

i have nested queries (the number variable it's useful me keeping same names) this:

select date_format(datetime, '%y-%m-%d %h:00:00') datetime (     select datetime (...) t ) t group datetime 

in sqlite group datetime evaulated on formatted date grouping takes place while in mysql plain passed datetime used have no grouping.

to better explain works in mysql brakes cycle having rename columns and/or tables as @ each loop:

select date_format(datetime, '%y-%m-%d %h:00:00') new_datetime (     select datetime (...) t ) t group new_datetime 

so, there way make mysql group datetime want?

if want group formatted datetime, pass group clause:

group date_format(datetime, '%y-%m-%d %h:00:00') 

this avoid multiple rows on different minutes/seconds.

to avoid calling date_format twice, can use like:

select @dtm := date_format(datetime, '%y-%m-%d %h:00:00') datetime tablename t group @dtm


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -