我如何筑巢这个组?

时间:2014-09-20 21:08:46

标签: sql

我的代码,说明“ 通过每个仓库内的分类列出手头的零件数量

    SELECT Warehouse, Class, Sum(OnHand) AS [Number of Parts]
    FROM Part
    Group BY Warehouse,Class

仓库总是分开的,我希望它有每个仓库和里面的清单 在里面,而是重复仓库 http://s16.postimg.org/golxkcdid/Untitled_1.jpg

结构 http://postimg.org/image/6exnykeod/

1 个答案:

答案 0 :(得分:1)

这可能会做你想要的,但这最好在Access'报告'中完成,而不是查询本身。

select v.warehouse, p.class, sum(p.onhand) as [Number of Parts]
  from part as p
  left outer join (select warehouse, min(class) as class
                     from part
                    group by warehouse) as v
    on p.warehouse = v.warehouse
   and p.class = v.class
 order by p.warehouse, p.class

要使用Access报告格式化结果 - 这是标准方法 - 您可以在此处找到说明:http://office.microsoft.com/en-us/access-help/create-a-grouped-or-summary-report-HA010006894.aspx