select A.*,B.*FROM 
(select '2:3酸99%' as 产品名称,
t1.fdecimal17 as 计划销售额
from  t_BOS200002351entry t1 ,t_BOS200002351 t
where t.fid=t1.fid and t.finteger=2000) A,
(select 
sum(fconsignamount) as 实际销售额
from ICStockBill i,ICStockBillentry i1
where i.finterid=i1.finterid  and i1.fitemid=154
and i.ftrantype=21
and year(i.fdate)=2011 group by i1.fitemid) B这是一条记录,还有多条记录需要union,
例如2:3酸98% i1.fitemid=153
这语句应该怎么写?
谢谢

解决方案 »

  1.   

            计划销售额,实际销售额
    2:3 酸99%,   44         55
    色酚           33         23名字是自己取的(根据itemid的不通),计划销售额是一个表的数据,实际是另一个表的数据语句杂写
      

  2.   

    这是一条记录,还有多条记录需要union,
    例如2:3酸98% i1.fitemid=153楼主这两个没有建表关联起来??
      

  3.   

    select A.*,B.*FROM  
    (select '2:3酸99%' as 产品名称,
    t1.fdecimal17 as 计划销售额
    from t_BOS200002351entry t1 ,t_BOS200002351 t
    where t.fid=t1.fid and t.finteger=2000) A,
    (select  
    sum(fconsignamount) as 实际销售额
    from ICStockBill i,ICStockBillentry i1
    where i.finterid=i1.finterid and i1.fitemid=154
    and i.ftrantype=21
    and year(i.fdate)=2011 group by i1.fitemid) Bunion all
    select A.*,B.*FROM  
    (select '2:3酸98%' as 产品名称,
    t1.fdecimal17 as 计划销售额
    from t_BOS200002351entry t1 ,t_BOS200002351 t
    where t.fid=t1.fid and t.finteger=2000) A,
    (select  
    sum(fconsignamount) as 实际销售额
    from ICStockBill i,ICStockBillentry i1
    where i.finterid=i1.finterid and i1.fitemid=153
    and i.ftrantype=21
    and year(i.fdate)=2011 group by i1.fitemid) B
    结果是这样的,怎么优化一下
      

  4.   

    ICStockBillentry这个表有fitemid,还有没有它对应的产品名称