GROUP BY TIME type field in Mysql

Asked

Viewed 27 times

0

In Mysql I have a table, one of the fields is of type TIME (TIME field).

inserir a descrição da imagem aqui

When making an appointment like this:

SELECT hora 
FROM tabela 
GROUP BY hora

Nothing is returned if I give GROUP BY in any other field, it works. Does this behavior make sense? If so, how to group the same results?

  • https://stackoverflow.com/a/25599108/4551469

  • caiocafardo, explain how you want the result to be because I’m thinking you want to make a ORDER BY. <--Link with example

1 answer

1

In the Mysql you need to "explain" how the grouping will be; I believe the most practical way is to define the date format in the select and using in group by country (link reference):

SELECT date_format(hora,'%Y-%m-%d %H-%i'), count(*)
FROM tabela 
GROUP BY 1
  • Thanks! But it’s not a DATETIME type, it’s a TIME type only, it works the same? Here did not give...

  • https://www.w3resource.com/mysql/date-and-time-functions/mysql-time_format-function.php. I understood this link to refer to a specific type method TIME, should work yes

Browser other questions tagged

You are not signed in. Login or sign up in order to post.