I am trying to select the most common hour a service has been requested.
I currently have a column
CALLOUT_TIME
14:12
12:55
13:18
17:55
14:00
14:45
19:00
05:20
And I want to pull out the most called upon hour in this case (14:00, 14 or 2pm).
I was hoping to group by Hour, or at least have a a count in desc order to highlight the most called upon.
The column is currently set at VARCHAR(2)
SELECT SUBSTR(CALLOUT_TIME, 1, 2) AS HH FROM REQUESTS;
Which will bring me:
HH
14
12
13
17
14
14
19
05 etc..
I was hoping to group by Hour, or at least have a a count in desc order to highlight the most called upon.
There is no DATETIME data type option and I cannot set as TIMESTAMP. Is there a reason I have no DATETIME option, am I using the wrong version of SQL Developer?
1条答案
按热度按时间n3schb8v1#
您使用
VARCHAR2
来存储时间,因为在Oracle中不存在TIME
数据类型。这是可以的。(您可以使用他们不恰当地称为DATE
的datetime数据类型,但这样您就必须使用一个虚拟日期。唯一的好处是您将有一个内置的有效时间检查。)你知道如何得到小时数,你说你想按小时分组,按计数排序,那么,这样做吧。