select distinct(K0212) as 库存,isnull(Max(K0228),'1900-01-01') as 结存日期 from K02 where K0212 in(select distinct(B1519) from B07
left join B15 with(readpast) on B0701=B1501 and B0702=B1517 where B0711='34') group by K0212
K0212和B1519相等
left join B15 with(readpast) on B0701=B1501 and B0702=B1517 where B0711='34') group by K0212
K0212和B1519相等
(
select distinct(B1519) B1519 from B07
left join B15 with(readpast) on B0701=B1501 and B0702=B1517 where B0711='34'
) n
where m.K0212 = n.B1519
group by m.K0212
(
select distinct(B1519) from B07
left join B15 with(readpast) on B0701=B1501 and B0702=B1517 where B0711='34'
)
select distinct(K0212) as 库存
,isnull(Max(K0228)
,'1900-01-01') as 结存日期
from K02 join CTE C on C.B1519=K0212
group by K0212
from K02 m , B07 n , B15 t
where m.K0212 = n.B1519 and n.B0701=t.B1501 and n.B0702=t.B1517 where n.B0711='34'
group by group by m.K0212后面那些条件,具体在哪个表,你看看。
isnull(Max(K0228),'1900-01-01') as 结存日期
from K02
where exists
(
select 1
from B07
left join B15 with(readpast) on B0701=B1501 and B0702=B1517
where B0711='34' and K0212=B1519
) group by K0212