获取错误:第18/11行错误:ORA-00923:在Oracle SQL中的预期位置未找到FROM关键字

pinkon5k  于 2023-01-08  发布在  Oracle
关注(0)|答案(1)|浏览(135)

我一直收到以下错误:“第18/11行错误:ORA-00923:FROM关键字未在预期位置找到”,并且我不确定原因。

SELECT my_records.my_date, h.reviewed_date, count(case when my_records.reviewed = 'Y' then 1 else null end), count(case when my_records.approved = 'Y' then 1 else null end), count(case when my_records.approved = 'N' then 1 else null end) as from 
(select h.id, 
  case 
    when :P43_DATE_RANGES = 'Monthly' then
      to_char(h.reviewed_date, 'Month') 
    when :P43_DATE_RANGES = 'Daily' then
      to_char(h.reviewed_date, 'MM/DD/YYYY') 
    when :P43_DATE_RANGES = 'Weekly' then
      to_char(TRUNC(h.reviewed_date, 'IW'), 'MM/DD/YYYY')
  end as my_date,  
    case 
    when :P43_DATE_RANGES = 'Monthly' then
      TRUNC(date_sys, 'MM') 
    when :P43_DATE_RANGES = 'Daily' then
      TRUNC(date_sys) 
    when :P43_DATE_RANGES = 'Weekly' then
      TRUNC(date_sys, 'IW')
  end as h.reviewed_date,
  h.reviewed, h.approved
FROM INGESTED i
LEFT OUTER JOIN highlighted h
ON i.id = h.id_ingested 
WHERE h.reviewed_date BETWEEN TO_DATE(:P43_START_DATE) AND TO_DATE(:P43_END_DATE)
) my_records
GROUP BY my_date, h.reviewed_date
olmpazwi

olmpazwi1#

这里的技巧是格式化查询,以便您了解它的结构。

SELECT 
    my_records.my_date, h.reviewed_date, 
    count(
        case when my_records.reviewed = 'Y' then 
            1 
        else 
            null 
        end), 
    count(
        case when my_records.approved = 'Y' then 
            1 
        else 
            null 
        end), 
    count(
        case when my_records.approved = 'N' then 
            1 
        else 
            null 
        end) as 
from 
    (select h.id, 
      case 
        when :P43_DATE_RANGES = 'Monthly' then
          to_char(h.reviewed_date, 'Month') 
        when :P43_DATE_RANGES = 'Daily' then
          to_char(h.reviewed_date, 'MM/DD/YYYY') 
        when :P43_DATE_RANGES = 'Weekly' then
          to_char(TRUNC(h.reviewed_date, 'IW'), 'MM/DD/YYYY')
      end as my_date,  
        case 
        when :P43_DATE_RANGES = 'Monthly' then
          TRUNC(date_sys, 'MM') 
        when :P43_DATE_RANGES = 'Daily' then
          TRUNC(date_sys) 
        when :P43_DATE_RANGES = 'Weekly' then
          TRUNC(date_sys, 'IW')
      end as h.reviewed_date,
      h.reviewed, h.approved
    FROM INGESTED i
    LEFT OUTER JOIN highlighted h
    ON i.id = h.id_ingested 
    WHERE h.reviewed_date BETWEEN TO_DATE(:P43_START_DATE) AND TO_DATE(:P43_END_DATE)
    ) my_records
GROUP BY my_date, h.reviewed_date

正如您所看到的,最后一个count后面跟着as,它通常用于提供别名,但是后面跟着from;这就是导致错误的原因。
as后提供别名或删除as

相关问题