码迷,mamicode.com
首页 > 其他好文 > 详细

查询两个表合并成一个表

时间:2018-07-11 14:41:53      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:The   group   union   sel   ase   查询   代理   sele   HERE   

select c.ClientID,c.Name,case MAX(c.Grade) when 0 then ‘厂家直营‘ when 1 then ‘总代理‘ when 2 then ‘省级代理‘when 3
then ‘省级代理‘ end Grade,MAX(d.CooperationIntention) as CooperationIntention,COUNT(*) as number,
ISNULL(c.IsEmphasis,0) IsEmphasis from SG_Client c inner join SG_Discuss d
on c.ClientID=d.ClientID where c.Leader=‘wzc‘ group by c.ClientID,c.Name,c.IsEmphasis
UNION ALL
select c.ClientID,c.Name,case MAX(c.Grade) when 0 then ‘厂家直营‘ when 1 then ‘总代理‘ when 2 then ‘省级代理‘when 3
then ‘省级代理‘ end Grade,MAX(d.CooperationIntention) as CooperationIntention,COUNT(*) as number,
2 IsEmphasis from SG_Client c inner join SG_Discuss d on c.ClientID=d.ClientID where
d.AssistDiscussPeople=‘wzc‘ group by c.ClientID,c.Name,c.IsEmphasis

查询两个表合并成一个表

标签:The   group   union   sel   ase   查询   代理   sele   HERE   

原文地址:https://www.cnblogs.com/heyiping/p/9293532.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!