|
发表于 2020-4-12 18:30:01
|
显示全部楼层
declare @tb_product table(p_code int, p_status int)
insert @tb_product
select 111, 7
union all select 222, 8
union all select 333, 9
declare @tb_usemode table(u_code int, u_status int)
insert @tb_usemode
select 111, 1
union all select 111, 1
union all select 222, 3
union all select 222 , 2
union all select 333 , 0
select p_code, u_code, p_status , u_status=min(u_status)
from @tb_product a inner join @tb_usemode b on a.p_code=b.u_code--这里的where 改为on
where u_status>0--排除楼主显示为看到有0这条记录
group by p_code, u_code, p_status
(所影响的行数为 3 行)
(所影响的行数为 5 行)
p_code u_code p_status u_status
----------- ----------- ----------- -----------
111 111 7 1
222 222 8 2
(所影响的行数为 2 行)
|
|