日期:2014-05-16 浏览次数:20410 次
--方法一
select c.Name,d.Name as OrgName,d.Code as OrgCode from
(select account.*,relation.OrganizationId from dbo.tb_Account_Organization as relation
right join dbo.tb_Account as account on relation.Accountid = account.Id)
as c left join dbo.tb_Organization as d on c.OrganizationId=d.Id
--方法二
with temp as (
select A.Name,C.OrganizationId
from tb_Account as A,tb_Account_Organization as C
where A.Id=C.AccountId
)
select T.Name,ORG.Name as OrgName,ORG.Code as OrgCode from
temp as T,tb_Organization as ORG
where T.OrganizationId=ORG.Id
--方法三
select T.Name,ORG.Name as OrgName,ORG.Code as OrgCode from
(
select A.Name,C.OrganizationId
from tb_Account as A,tb_Account_Organization as C
where A.Id=C.AccountId
) as T,tb_Organization as ORG
where T.OrganizationId=ORG.Id