我是查询出来的两张数据表,现在需要合并为一张表方便使用,请看sql语句
SELECT A.User_Name ,A.PhoneNo ,A.OICQ ,C.RoleCode ,D.Value AS RoleName ,G.CompanyName ,G.Address AS CompanyAddress ,G.Telephone AS CompanyTel,F.PropertyInstance_Value FROM Base_UserInfo A LEFT JOIN Base_UserRole B ON A.User_ID = B.User_ID LEFT JOIN Base_Roles C ON B.Roles_ID = C.Roles_ID LEFT JOIN TMSTCommonData D ON C.RoleCode = D.Code AND D.CodeKey = 'ChatUserRole', TMSTCompany G,Base_AppendPropertyInstance F WHERE A.CompanyCode = G.CompanyCode
AND (A.User_ID=F.PropertyInstance_Key AND F.Property_Control_ID='QrWeChatPath') AND A.User_Account = '18381091656'
SELECT F.PropertyInstance_Value as Usercode from Base_UserInfo A,Base_AppendPropertyInstance F where A.User_Account='18381091656' and A.User_ID=F.PropertyInstance_Key
AND F.Property_Control_ID='PromotionCode'
有人私下帮我解决下更好,我可以给你发图详细看
---说明:Sql 之union 的方法,有关资料,可以百度了解。以下是写好的Sql语句,请自己试下。
SELECT A.User_Name ,
A.PhoneNo ,
A.OICQ ,
C.RoleCode ,
D.Value AS RoleName ,
G.CompanyName ,
G.Address AS CompanyAddress ,
G.Telephone AS CompanyTel,
F.PropertyInstance_Value as Usercode
FROM Base_UserInfo A LEFT JOIN Base_UserRole B ON A.User_ID = B.User_ID LEFT JOIN Base_Roles C ON B.Roles_ID = C.Roles_ID LEFT JOIN TMSTCommonData D ON C.RoleCode = D.Code AND D.CodeKey = 'ChatUserRole', TMSTCompany G,Base_AppendPropertyInstance F WHERE A.CompanyCode = G.CompanyCode
AND (A.User_ID=F.PropertyInstance_Key AND F.Property_Control_ID='QrWeChatPath') AND A.User_Account = '18381091656'
union
SELECT
'' as User_Name ,
'' as PhoneNo ,
'' as OICQ,
'' as RoleCode,
'' as RoleName,
'' as CompanyName,
'' as CompanyAddress,
'' as CompanyTel,
F.PropertyInstance_Value as Usercode
from Base_UserInfo A,Base_AppendPropertyInstance F where A.User_Account='18381091656' and A.User_ID=F.PropertyInstance_Key
AND F.Property_Control_ID='PromotionCode'
大哥,把你QQ给我,我发图给你看看
@jinggege: N年前就不用QQ了,可以把图片放到这里来。
@chenaran: 还是这个排版看着舒服~