|
我有两个SQL语句,单独运行时都是正常的,但用Union all合并在一起时却发生错误;特别是“区域经理”字段
SQL 一:(select sj1.*,客户.区域经理,客户.区域 from(select sj.*,产品.产品类别, 产品.产品型号 from (SELECT "实际销售" as 销售,"" as 预算,订单.订单ID,订单.公司名称,format(订单.销售日期,"yyyymm") as 月份,订单明细.产品名称,订单明细.数量 as 销售数量,0 As 预算数量,订单明细.单价,订单明细.金额 as 销售金额,0 as 预算金额
FROM 订单 INNER JOIN 订单明细 ON 订单.订单ID = 订单明细.订单ID where 订单明细.类型 in ("打折","费用","三等奖","销售") and 订单.公司名称<>"零售") as sj inner join 产品 on sj.产品名称=产品.产品名称) as sj1 left join 客户 on sj1.公司名称=客户.公司名称 where 客户.区域经理 is not null)
SQL 二:(select ys.*, "预算" as 区域经理, "" as 区域,产品.产品类别, 产品.产品型号 from (SELECT "" as 销售,"销售预算" as 预算, "" as 订单ID, "" as 公司名称,format(销售预算.月份,"YYYYMM") as 月份, 销售预算.产品名称, 0 as 销售数量,销售预算.数量 as 预算数量, 销售预算.单价, 0 as 销售金额,销售预算.金额 as 预算金额
FROM 销售预算) as ys inner join 产品 on ys.产品名称=产品.产品名称)
合并后:(select sj1.*,客户.区域经理,客户.区域 from(select sj.*,产品.产品类别, 产品.产品型号 from (SELECT "实际销售" as 销售,"" as 预算,订单.订单ID,订单.公司名称,format(订单.销售日期,"yyyymm") as 月份,订单明细.产品名称,订单明细.数量 as 销售数量,0 As 预算数量,订单明细.单价,订单明细.金额 as 销售金额,0 as 预算金额
FROM 订单 INNER JOIN 订单明细 ON 订单.订单ID = 订单明细.订单ID where 订单明细.类型 in ("打折","费用","三等奖","销售") and 订单.公司名称<>"零售") as sj inner join 产品 on sj.产品名称=产品.产品名称) as sj1 left join 客户 on sj1.公司名称=客户.公司名称 where 客户.区域经理 is not null) union all (select ys.*, "预算" as 区域经理, "" as 区域,产品.产品类别, 产品.产品型号 from (SELECT "" as 销售,"销售预算" as 预算, "" as 订单ID, "" as 公司名称,format(销售预算.月份,"YYYYMM") as 月份, 销售预算.产品名称, 0 as 销售数量,销售预算.数量 as 预算数量, 销售预算.单价, 0 as 销售金额,销售预算.金额 as 预算金额
FROM 销售预算) as ys inner join 产品 on ys.产品名称=产品.产品名称)
请各位老师帮忙看看是怎么回事?
[ 本帖最后由 fankairong 于 2011-7-1 15:41 编辑 ] |
|