search

Home  >  Q&A  >  body text

Convert SQL query to display output in time format

This is the data I'm using in a SQL database:

Symbol |  High_Time
  AAPL   10:01:00.000        
  TSLA   09:45:00.000                
  AAPl   10:05:00.000
  AAPL   01:15:00.000        
  SPY    09:30:00.000                
  TSLA   09:48:00.000      
  SPY    09:30:00.000                
  AAPL   11:01:00.000

SQL query that I used to get the average of the HOD_time column:

SELECT Symbol, AVG(High_Time) FROM data GROUP BY Symbol;

Output (example):

Symbol | (AVG)High_Time
  AAPL   33400.00000000        
  TSLA   107000.00000000                      
  SPY    120000.00000000

It displays numbers instead of time format. How would you make the query display in time format?

Desired output (example):

Symbol | (AVG)High_Time
  AAPL   8:05        
  TSLA   9:46                     
  SPY    9:30

P粉704066087P粉704066087228 days ago379

reply all(1)I'll reply

  • P粉321584263

    P粉3215842632024-04-05 00:35:04

    What you are looking for is

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

    reply
    0
  • Cancelreply