union all的使用报错,单独对每段代码取数可以,但是通过union all将两端数据拼接不行?

select a.khm as 客户名称,(select xm from uf_khgl where id=a.khm) as 客户名称显示

,a.jssr as 结算收入

,a.ddfwjl as 订单服务经理,(select lastname from dbo.[HrmResource] where id=a.ddfwjl) as 员工显示

,case when a.dkjedw=1 then a.dkje*a.hl/10000 else a.dkje*a.hl end as 销量

from uf_ddgl a

where a.jsfs='1' and a.ddzt in('2','3') and a.jsrq>='${ksrq}' and a.jsrq<='${jsrq}'

union all

select a.khm as 客户名称,(select xm from uf_khgl where id=a.khm) as 客户名称显示

,a.ddfwjl as 订单服务经理,(select lastname from dbo.[HrmResource] where id=a.ddfwjl) as 员工显示

,case when a.dkjedw=1 then a.dkje*a.hl/10000 else a.dkje*a.hl end as 销量

,b.jssr as 结算收入

,b.srgx as 收入贡献

from uf_ddgl a

left join uf_ddgl_dt1 b on b.mainid=a.id

where a.jsfs='0' and a.ddzt in('2','3') and b.jxrq>='${ksrq}' and b.jxrq<='${jsrq}'


baibian 发布于 2019-5-28 10:33
1min目标场景问卷 立即参与
回答问题
悬赏:4 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
虾米、木木Lv2初级互助
发布于2019-5-28 10:41

UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。


  • 2关注人数
  • 417浏览人数
  • 最后回答于:2019-5-28 10:41
    请选择关闭问题的原因
    确定 取消
    返回顶部