2

这是我的 oracle 查询..我尝试了很多,但它显示不同的错误我的条件是显示 12 个月,如果没有数据显示 0 值,如果数据只显示值.....

select distinct 
COUNTRY_NAME,                       
TRAN_DATE,
ROUND (nvl(sum(WALKIN_WITHOUT_CGROUP),0)/ COUNT(*),2)APC,
ROUND((nvl(SUM(SALES_VALUE),0)+nvl(sum(total_sales),0)-nvl(sum(net_sales),0)+nvl(sum(discount),0))/nvl(sum(BILLS_WITHOUT_CGROUP),0))ASPB,
ROUND((nvl(SUM(SALES_VALUE),0)+nvl(sum(total_sales),0)-nvl(sum(net_sales),0)+nvl(sum(discount),0))/COUNT(*),2) ASPD,
nvl(sum(BILLS_WITHOUT_CGROUP),0) Bill,
trunc(nvl(SUM(SALES_VALUE),0)+nvl(sum(total_sales),0)-nvl(sum(net_sales),0)+nvl(sum(discount),0)) Sale,
nvl(sum(WALKIN_WITHOUT_CGROUP),0) WALKINS
from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B
WHERE  A.OUTLET_ID=B.OUTLET_ID and SALES_VALUE>0
and rownum <=300
group by COUNTRY_NAME,                      
TRAN_DATE

所需的输出应该是这样的:

MONTH          APC             sale
----- -------           

    01          0      0
    02          0      0
    03          0      0
    04          0      12    
    05          0      14
    06          1       0
    07          1       0
    08          0       0
    09          0       0
    10          2       0
    11          1       0
    12          0       0
4

2 回答 2

1

您必须在 select 语句中的列之间使用逗号

    select '01', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '02', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '03', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '04', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '05', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '06', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '07', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '08', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '09', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '10', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '11', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT A,OUTLET_DETAILS B union all
select '12', to_char(tran_date,'mm') from OUTLET_PAYMODE_REPORT_FACT
于 2013-08-27T07:51:08.513 回答
1

根据我的经验,10 例中有 8 例

ORA-00923: FROM keyword not found where expected

错误是由于缺少逗号

于 2013-08-27T09:42:20.120 回答