求一条SQL语句
表A 类型表 (ID,类型)
表B 商品表(ID,A.ID(与A表关联字段),商品名,金额)
查出下面的结果来
如表A有:
ID 类型
1 饮料
表B有:
ID,A.ID,商品名,金额
1 1 红茶 2
2 1 绿茶 3
所要结果:
饮料,5
红茶,2
绿茶,3
[解决办法]
Select [类型] As '类型', (Select Sum([金额]) From [B] Where AID = A.ID) As '金额'
From A
Union
Select [商品名] As '类型', [金额] As '金额'
From B
[解决办法]