Home > Net >  SQL Removing Milliseconds from a SQL query
SQL Removing Milliseconds from a SQL query

Time:05-28

My Query is:

SELECT Symbol, SEC_TO_TIME(AVG(TIME_TO_SEC(High_Time))) as AvgTime FROM data GROUP BY Symbol;

Output:

Symbol    AvgTime   
 AAPL  03:34:00.0000
 TSLA  10:50:00.0000
 SHOP  03:40:00.0000

How would you change the query so the output looks like this?

Symbol  AvgTime 
 AAPL  03:34:00
 TSLA  10:50:00
 SHOP  03:40:00

CodePudding user response:

You could simply apply the ROUND function on the value being converted to a time string eg:

SEC_TO_TIME(ROUND(AVG(TIME_TO_SEC(High_Time)))) as AvgTime
  • Related