最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Oracle 計算時間格式平均值的sql 語句

 更新時間:2019年08月27日 16:03:12   作者:虎咆狼哮  
這篇文章主要介紹了Oracle 計算時間格式平均值的sql 語句,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下

Oracle 計算時間格式平均值的sql 語句

select 
to_char((to_date('2019-07-01', 'yyyy-mm-dd') + numtodsinterval(avg(begin_time_second), 'second')),'hh24:mi:ss') avg_begin_time,
to_char((to_date('2019-07-01', 'yyyy-mm-dd') + numtodsinterval(avg(end_time_second), 'second')),'hh24:mi:ss') avg_end_time
--2019-07-01 00:00:00 + numtodsinterval(平均數(shù),'秒')轉(zhuǎn)換為日期格式,然后再轉(zhuǎn)換為 時間字符格式
from 
(
  select 
  --把上班時間換算為秒
  to_char(a.actontime, 'hh24') * 3600 +
  to_char(a.actontime, 'mi') * 60 +
  to_char(a.actontime, 'ss') as begin_time_second,
  --把下班時間換算為秒 
  to_char(a.actofftime, 'hh24') * 3600 +
  to_char(a.actofftime, 'mi') * 60 + 
  to_char(a.actofftime, 'ss') as end_time_second
  from empworkdate a
)

知識點擴展:oracle中獲取年月日時分秒

我寫sql的時間為2016年10月10日下午15:18完事,這個時間下面要做對比:

--獲取年
select to_char(sysdate,'yyyy') from dual--2016
select to_char(sysdate,'YYYY') from dual--2016
--獲取月
select to_char(sysdate,'mm') from dual--10
select to_char(sysdate,'MM') from dual--10
--獲取日
select to_char(sysdate,'dd') from dual--10
select to_char(sysdate,'DD') from dual--10
--獲取時
select to_char(sysdate,'hh24') from dual--15
select to_char(sysdate,'hh') from dual--03
select to_char(sysdate,'HH') from dual--03
select to_char(sysdate,'HH24') from dual--15
--獲取分鐘
select to_char(sysdate,'MI') from dual--14
select to_char(sysdate,'mi') from dual--14
--獲取秒
select to_char(sysdate,'ss') from dual--35
select to_char(sysdate,'SS') from dual--40
--獲取年月日時分秒
select to_char(sysdate,'yyyy-mm-dd hh:mi:ss') from dual--2016-10-10 03:17:25
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual--2016-10-10 15:17:51

(1)從上面的測試SQL可以看出年月日yyyy,mm,dd,hh,mi,ss的大小寫對于從oracle中獲取年月日時分秒沒有影響

(2)對于獲取小時分12小時和24小時的情況,如果你想獲取顯示下午的時間,你可以采用hh24,這樣就會顯示類似于15:30而不是03:30

總結(jié)

以上所述是小編給大家介紹的Oracle 計算時間格式平均值的sql 語句,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

最新評論

井陉县| 彩票| 金山区| 长泰县| 临泉县| 莱州市| 莱西市| 宁阳县| 济宁市| 铁岭县| 彭阳县| 东平县| 从江县| 五常市| 东乌珠穆沁旗| 祁阳县| 辉南县| 吴川市| 花莲县| 砀山县| 嵊泗县| 丰顺县| 安仁县| 新津县| 景泰县| 祁连县| 香格里拉县| 惠水县| 加查县| 阳春市| 抚顺市| 怀宁县| 佛教| 汕尾市| 都兰县| 普陀区| 德阳市| 加查县| 白城市| 昌乐县| 汝城县|