34,838
社区成员




create table HouseInfo
(
id int,
chargetype int,
wuyetype int
)
insert into HouseInfo
values(1,2,3)
select *
from HouseInfo
create table ChargeType
(
id int,
name varchar(50)
)
insert into ChargeType
select 1 , '每月付款' union all
select 2 , '每季付款' union all
select 3 , '每年付款'
select * from ChargeType
create table WuYeType
(
id int,
name varchar(50)
)
insert into WuYeType
select 1,'住房' union all
select 2, '写字楼' union all
select 3 , '铺面' union all
select 4 , '厂房'
select * from WuYeType
select a.id,a.[name],c.[name]
from WuYeType a left join HouseInfo b
on a.id=b.wuyetype
left join ChargeType c on b.wuyetype=c.id
--结果:
/*
id name name
----------- -------------------------------------------------- --------------------------------------------------
1 住房 NULL
2 写字楼 NULL
3 铺面 每年付款
4 厂房 NULL
(所影响的行数为 4 行)
*/
create table HouseInfo
(
id int,
chargetype int,
wuyetype int
)
insert into HouseInfo
values(1,2,3)
select *
from HouseInfo
create table ChargeType
(
id int,
name varchar(50)
)
insert into ChargeType
select 1 , '每月付款' union all
select 2 , '每季付款' union all
select 3 , '每年付款'
select * from ChargeType
create table WuYeType
(
id int,
name varchar(50)
)
insert into WuYeType
select 1,'住房' union all
select 2, '写字楼' union all
select 3 , '铺面' union all
select 4 , '厂房'
select a.id,a.name,c.name
from WuYeType a left join HouseInfo b
on a.id=b.wuyetype
left join ChargeType c on b.ChargeType=c.id
--结果:
/*
id name name
----------- -------------------------------------------------- --------------------------------------------------
1 住房 NULL
2 写字楼 NULL
3 铺面 每季付款
4 厂房 NULL
(所影响的行数为 4 行)
*/