0
select  ((normalcost*25*0.5)+(schoolcost*25)) as "projectedcost" 
from    (   select  count(orderno) as normalcost 
            from    platterorder 
            where to_char(deliveryDate,'MON-YYYY')='APR-2013'
        ),
        (   select  count(orderno) as schoolcost 
            from    schoolorder 
            where to_char(deliveryDate,'MON-YYYY')='APR-2013'
        );

上面的代码运行良好,但是当我尝试添加 discountpercent 列代替 0.5 时,它显示错误

相关表格如下

PlatterOrder
(   orderNo, 
    deliveryDate, 
    deliveryTime, 
    invoiced, 
    isBulk, 
    platterQuantity, 
    discountPercent, 
    clientNo        
)

SchoolOrder
(   orderNo, 
    deliveryDate, 
    deliveryTime, 
    invoiced, 
    taxExPercent,
    clientNo
);
4

2 回答 2

0

它显示错误,因为列 discountPercent 未在查询中的任何位置声明 - 您需要以某种方式添加它。你需要多少折扣百分比?例如,如果您不想使用月份的平均值,请使用以下查询:

select  ((normalcost*25*avgdiscountPercent)+(schoolcost*25)) as "projectedcost" 
from    (   select  count(orderno) as normalcost 
            from    platterorder 
            where to_char(deliveryDate,'MON-YYYY')='APR-2013'
        ),
        (   select  count(orderno) as schoolcost 
            from    schoolorder 
            where to_char(deliveryDate,'MON-YYYY')='APR-2013'
        ),
        (select avg(discountPercent) as avgdiscountPercent
            from platterorder
            where to_char(deliveryDate,'MON-YYYY')='APR-2013'
        );
于 2013-06-02T21:26:18.370 回答
0

我不确定我是否遵循您的代码,但您没有在任何地方选择 discountpercent 列。它不适用于 SELECT 子句,因为您只选择了两个子查询中的其他字段。如果您的示例有效,并且您每月只有一个折扣率,那么类似于:

select ((normalcost*25*0.5)+(schoolcost*25)) as "projectedcost" 
from (select count(orderno) as normalcost 
      from platterorder where to_char(deliveryDate,'MON-YYYY')='APR-2013')
  , (select count(orderno) as schoolcost 
     from schoolorder where to_char(deliveryDate,'MON-YYYY')='APR-2013');
  , (select DISTINCT discountpercent  as discountpercent  
     from platterorder where to_char(deliveryDate,'MON-YYYY')='APR-2013');

整个结构很奇怪,没有加入,贴现率只是按月变化吗?

于 2013-06-02T14:50:49.363 回答