我正在運行整個查詢並且一切運行正常,直到最後我得到錯誤(標題),輸出應該像下面的excel圖像。我已經嘗試保持小時爲char和num和date,但是我仍然收到錯誤。任何幫助,將不勝感激。請隨時提問並檢查工具中的代碼。由於Oracle SQL - 小時必須在0到23之間錯誤
with ht as(
select labno, birthdt, spectype,
--to_char(
((dtrecv - dtcoll)
+ (to_date(nvl(tmrecv, '0000'), 'hh24mi')
- to_date(nvl(tmcoll, '0000'), 'hh24mi'))
) * 24
--, 'hh24:mi')
as hours
from azmsds.sample_demog_view
where tmrecv is not null and tmcoll is not null and dtrecv is not null and dtcoll is not null
),
secondQuery AS (
select
ht.hours,
extract(year from ht.birthdt) as "YEAR",
extract (month from ht.birthdt) as "MONTH",
count(distinct ht.labno) as "initialDbsReceiptCount<1",
'~' AS EOL
from ht
where 1=1
and ht.hours is not null
--and month not null
AND ht.birthdt >= '01-JAN-12'
-- and hours <= 23
and ht.spectype in (1,5,7)
--and hours > 23
group by extract(year from ht.birthdt), extract (month from ht.birthdt), ht.hours
order by extract(year from ht.birthdt) desc
),
ThirdQuery AS (
SELECT
sq.year,
sq.month,
sq."initialDbsReceiptCount<1",
sq.eol
FROM secondQuery sq
WHERE 1=1
--AND sq.hours <= 24
)
select * from ThirdQuery