2,507
社区成员
发帖
与我相关
我的任务
分享
create table a (
BNo varchar(4),
Standard varchar(20),
Status smallint,
Num smallint)
create table b (
BNo varchar(4),
Standard varchar(20))
Insert into a(bno, standard, status, num)
values('0001', '1700*1000', 1, 1)
Insert into a(bno, standard, status, num)
values('0002', '500*800', 0, 1)
Insert into b(bno, standard)
values('0001', '1000*1000')
Insert into b(bno, standard)
values('0001', '700*1000')
select bno, standard, num from
(select * from a where status <> 1
union all
select
b.*,
0 as status,
0 as num
from
b inner join a on (a.bno = b.bno)
where
a.status = 1
)
--a為表一,b為表二
select a.編碼,b.規格,a.數量
from a left join b on b.編碼=a.編碼
where a.狀態='1' select 表一.编码, 表二.规格, 表一.数量
from 表一 left join 表二 on 表二.编码 = 表一.编码
where 表一.状态 = '1'