Tabel A:
name b_type qty
外套画报 B 10
外套画报 C 5
Tabel B:
id b_type
1 A
2 B
3 C
4 D
需要结果:
name b_type qty percent
外套画报 A 0 0%
外套画报 B 10 67%
外套画报 C 5 33%
外套画报 D 0 0%
------解决方案--------------------
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-09-10 09:49:43
-- Version:
-- Microsoft SQL Server 2014 (CTP1) - 11.0.9120.5 (X64)
-- Jun 10 2013 20:09:10
-- Copyright (c) Microsoft Corporation
-- Enterprise Evaluation Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------
--> 测试数据:[TabelA]
if object_id('[TabelA]') is not null drop table [TabelA]
go
create table [TabelA]([name] varchar(8),[b_type] varchar(1),[qty] int)
insert [TabelA]
select '外套画报','B',10 union all
select '外套画报','C',5
--> 测试数据:[TabelB]
if object_id('[TabelB]') is not null drop table [TabelB]
go
create table [TabelB]([id] int,[b_type] varchar(1))
insert [TabelB]
select 1,'A' union all