27,579
社区成员
发帖
与我相关
我的任务
分享
create table t1(gd_id varchar(10),gd_name nvarchar(10),gd_model nvarchar(10))
insert into t1 select '001','青霉素','500万单位'
insert into t1 select '002','安定片','100片/瓶'
insert into t1 select '003','注射器','支'
create table t2(gd_id varchar(10),gd_name varchar(10),gd_count int,gd_price int,gd_money int)
insert into t2 select '001','青霉素',3 ,5 ,15
insert into t2 select '002','安定片',10 ,1 ,10
insert into t2 select 'A01','住院费',1 ,15 ,15
insert into t2 select 'A02','B超',1 ,35 ,35
go
select a.*,b.gd_model
from t2 a left join t1 b on a.gd_id=b.gd_id
/*
gd_id gd_name gd_count gd_price gd_money gd_model
---------- ---------- ----------- ----------- ----------- ----------
001 青霉素 3 5 15 500万单位
002 安定片 10 1 10 100片/瓶
A01 住院费 1 15 15 NULL
A02 B超 1 35 35 NULL
(4 行受影响)
*/
go
drop table t1,t2
select b.*,a.gd_model from 表B b
left join 表A a on b.gd_id=a.gd_id
select B.* ,a.gd_model from b left join a where b.gd_id = a.gd_id
select
b.*,a.gd_model
from
b left join a
on
b.gd_id =a.gd_id