1.select a.商品CD,isnull(b.商品类别,c.商品类别) as 商品类别 from a,b,c where a.商品CD=b.商品CD and a.商品CD=c.商品CD
select 商品CD,'表B.'+(select 商品类别 from B where B.商品CD=A.商品CD) 商品类别 from A union all select 商品CD,'表B.'+(select 商品类别 from C where C.商品CD=A.商品CD) 商品类别 from A where A.商品CD not in (select 商品CD from B)
2. select 商品分类, count(*) 个数 from tablename group by 商品分类
ft,又犯了个小错误 select 商品CD,'表B.'+(select 商品类别 from B where B.商品CD=A.商品CD) 商品类别 from A union all select 商品CD,'表C.'+(select 商品类别 from C where C.商品CD=A.商品CD) 商品类别 from A where A.商品CD not in (select 商品CD from B)
from a,b,c where a.商品CD=b.商品CD and a.商品CD=c.商品CD
union all
select 商品CD,'表B.'+(select 商品类别 from C where C.商品CD=A.商品CD) 商品类别 from A where A.商品CD not in (select 商品CD from B)
select 商品CD,'表B.'+(select 商品类别 from B where B.商品CD=A.商品CD) 商品类别 from A
union all
select 商品CD,'表C.'+(select 商品类别 from C where C.商品CD=A.商品CD) 商品类别 from A where A.商品CD not in (select 商品CD from B)