0
運行以下ORACLE語句時出現ORA-00937
錯誤,我對Oracle很陌生(T-SQL更多是我的包)。我已經轉換了以前使用SQL編寫的select語句,因爲所有列都是sum'd,所以它爲什麼期望一個組......這是轉換的select語句(我目前正在運行/測試這些用sqlplus):ORA-00937不是從SQL Server轉換而來的單組功能
select
round(COALESCE(
(COALESCE((select SUM((F_BOOK_DATES.BKD_ADATE_ENDS - F_BOOK_DATES.BKD_ADATE_START) * (60 * 24)) FROM F_BOOK_DATES
INNER JOIN F_BOOK_HEADER ON F_BOOK_DATES.BKD_FKEY_BK_SEQ = F_BOOK_HEADER.BK_SEQ
and EXTRACT (YEAR from F_BOOK_DATES.BKD_DATE_START) = EXTRACT (YEAR from SYSDATE)
and EXTRACT (MONTH from F_BOOK_DATES.BKD_DATE_START) = EXTRACT (MONTH from SYSDATE)
and EXTRACT (DAY from F_BOOK_DATES.BKD_DATE_START) = EXTRACT (DAY from SYSDATE)
AND F_BOOK_HEADER.BK_STATUS NOT IN ('CX','TP')
AND F_BOOK_HEADER.Deleted <> 1
AND F_BOOK_DATES.Deleted <> 1),9999999999.99,0)
/sum(case when FAREALO.AllDayBooking = 1 then 1400 else
((FAREALO.LO_TIME_END - FAREALO.LO_TIME_START) * (60 * 24)) end) * 100),0),2) as "PercentUtilised"
from FAREALO
inner join F_LO_TYPE on FAREALO.LO_FKEY_LOT_SEQ = F_LO_TYPE.LOT_SEQ
where FAREALO.LO_BK_LOCATION = 1
and LOT_CBS = 1;
這是SQL語句(的作品),我試過上述轉換:
select
round(isnull(
(isnull(convert (DECIMAL(10,2),(select SUM(datediff(n,BKD_ADATE_START, BKD_ADATE_ENDS)) FROM F_BOOK_DATES with (NOLOCK)
INNER JOIN F_BOOK_HEADER with (NOLOCK) ON BKD_FKEY_BK_SEQ = BK_SEQ
AND DATEPART(YYYY,BKD_DATE_START) = DATEPART(YYYY,GETDATE())
AND DATEPART(MM,BKD_DATE_START) = DATEPART(MM,GETDATE())
AND DATEPART(DD,BKD_DATE_START) = DATEPART(DD,GETDATE())
AND BK_STATUS NOT IN ('CX','TP')
AND F_BOOK_HEADER.Deleted <> 1
AND F_BOOK_DATES.Deleted <> 1)),0)
/
sum(case when AllDayBooking = 1 then 1400 else
datediff(n,LO_TIME_START, LO_TIME_END) end) * 100),0),2) as PercentUtilised
from FAREALO with (NOLOCK)
inner join F_LO_TYPE with (NOLOCK) on LO_FKEY_LOT_SEQ = LOT_SEQ
where LO_BK_LOCATION = 1
and LOT_CBS = 1
任何人看看我錯過了什麼?
感謝
Ĵ
是否可以編輯您的問題,包括表定義?我不知道哪些列屬於哪個表。此外,如果您使用它們來自的表來標識查詢中的所有列(例如,不是編寫'BK_STATUS',編寫'F_BOOK_HEADER.BK_STATUS'等等),它有幫助嗎? –
我已將完整的表格添加到上面的Oracle查詢中。 儘管已將MIN添加到總和的第一部分(第3行,因爲此部分已多次帶回相同的值),現在查詢運行 – user2241693