select * from (select u1.FbillNo as 销售订单号,u1.fdate as 日期,u3.fname as 部门,u4.fname as 客户,u2.Fprice as 单价,u5.fname as 币别,u1.fexchangerate as 汇率,u2.fcess as 税率,u2.fqty as 订单数量,u2.fstockqty as 出库数量,u2.fqty-u2.fstockqty as 未交数量,u2.fqty*fprice as 订单金额,u2.fqty*U2.fprice*U1.fexchangerate as 订单本位币金额,(u2.fqty-u2.fstockqty)*u2.Fprice as 未交金额,(u2.fqty-u2.fstockqty)*u2.Fprice*U1.fexchangerate as 未交本位币金额,(u2.fqty-u2.fstockqty)*u2.Fprice*(1-u2.fcess)*U1.fexchangerate as 未交除税本位币金额 from seorder u1 left join seorderentry u2 on u1.finterid=u2.finterid left join t_department u3 on u1.fdeptid=u3.fitemid left join t_organization u4 on u1.fcustid=u4.fitemid left join t_currency u5 on u1.fcurrencyid=u5.fcurrencyid where u1.fclosed<>1 and u1.fdate>='2009-11-01' and u1.fdate<='2010-01-18' and u2.fqty>u2.fstockqty) a group by 未交金额,未交本位币金额 with rollup实现结果:
就是合计未交金额与未交本位币金额。现在报错。

解决方案 »

  1.   

    select * from 
    (
    select u1.FbillNo as 销售订单号,
    u1.fdate as 日期,
    u3.fname as 部门,
    u4.fname as 客户,
    u2.Fprice as 单价,
    u5.fname as 币别,
    u1.fexchangerate as 汇率,
    u2.fcess as 税率,
    u2.fqty as 订单数量,
    u2.fstockqty as 出库数量,
    u2.fqty-u2.fstockqty as 未交数量,
    u2.fqty*fprice as 订单金额,
    u2.fqty*U2.fprice*U1.fexchangerate as 订单本位币金额,
    (u2.fqty- u2.fstockqty)*u2.Fprice as 未交金额,
    (u2.fqty-u2.fstockqty)*u2.Fprice*U1.fexchangerate as 未交本位币金额,
    (u2.fqty-u2.fstockqty)*u2.Fprice*(1-u2.fcess)*U1.fexchangerate as 未交除税本位币金额 from seorder u1 
    left join seorderentry u2 on u1.finterid=u2.finterid 
    left join t_department u3 on u1.fdeptid=u3.fitemid 
    left join t_organization u4 on u1.fcustid=u4.fitemid 
    left join t_currency u5 on u1.fcurrencyid=u5.fcurrencyid 
    AND u1.fclosed <>1 and u1.fdate>='2009-11-01' and u1.fdate <='2010-01-18' and u2.fqty>u2.fstockqty) a 
    group by 未交金额,未交本位币金额 with rollup GROUP BY 不能这样用吧,聚合函数都没有?
      

  2.   

    select
    你的分组字段....
     SUM (未交金额)AS 合计未交金额,
     SUM(未交本位币金额)AS 合计未交本位币金额from 
    (
    select u1.FbillNo as 销售订单号,
    u1.fdate as 日期,
    u3.fname as 部门,
    u4.fname as 客户,
    u2.Fprice as 单价,
    u5.fname as 币别,
    u1.fexchangerate as 汇率,
    u2.fcess as 税率,
    u2.fqty as 订单数量,
    u2.fstockqty as 出库数量,
    u2.fqty-u2.fstockqty as 未交数量,
    u2.fqty*fprice as 订单金额,
    u2.fqty*U2.fprice*U1.fexchangerate as 订单本位币金额,
    (u2.fqty- u2.fstockqty)*u2.Fprice as 未交金额,
    (u2.fqty-u2.fstockqty)*u2.Fprice*U1.fexchangerate as 未交本位币金额,
    (u2.fqty-u2.fstockqty)*u2.Fprice*(1-u2.fcess)*U1.fexchangerate as 未交除税本位币金额 from seorder u1 
    left join seorderentry u2 on u1.finterid=u2.finterid 
    left join t_department u3 on u1.fdeptid=u3.fitemid 
    left join t_organization u4 on u1.fcustid=u4.fitemid 
    left join t_currency u5 on u1.fcurrencyid=u5.fcurrencyid 
    AND u1.fclosed <>1 and u1.fdate>='2009-11-01' and u1.fdate <='2010-01-18' and u2.fqty>u2.fstockqty) a 
    group by 你的分组字段 with rollup 
      

  3.   

    没有聚合函数 怎么来group by ??
    你的分组字段是哪些??就是group by 后面加的
      

  4.   


    select
    未交金额,未交本位币金额,
    ---这里写聚合函数 比如sum,count,max,min等from 
    (
        select u1.FbillNo as 销售订单号,
        u1.fdate as 日期,
        u3.fname as 部门,
        u4.fname as 客户,
        u2.Fprice as 单价,
        u5.fname as 币别,
        u1.fexchangerate as 汇率,
        u2.fcess as 税率,
        u2.fqty as 订单数量,
        u2.fstockqty as 出库数量,
        u2.fqty-u2.fstockqty as 未交数量,
        u2.fqty*fprice as 订单金额,
        u2.fqty*U2.fprice*U1.fexchangerate as 订单本位币金额,
        (u2.fqty- u2.fstockqty)*u2.Fprice as 未交金额,
        (u2.fqty-u2.fstockqty)*u2.Fprice*U1.fexchangerate as 未交本位币金额,
        (u2.fqty-u2.fstockqty)*u2.Fprice*(1-u2.fcess)*U1.fexchangerate as 未交除税本位币金额 from seorder u1 
        left join seorderentry u2 on u1.finterid=u2.finterid 
        left join t_department u3 on u1.fdeptid=u3.fitemid 
        left join t_organization u4 on u1.fcustid=u4.fitemid 
        left join t_currency u5 on u1.fcurrencyid=u5.fcurrencyid 
    AND u1.fclosed <>1 and u1.fdate>='2009-11-01' and u1.fdate <='2010-01-18' and u2.fqty>u2.fstockqty) a 
    group by 未交金额,未交本位币金额 with rollup