【发布时间】:2015-11-19 12:00:46
【问题描述】:
我在 MS Access 2013 中开发了一个数据库。 我需要从两个表中生成报告:inventory_type、inventory(以及一些 T-SQL 经验)
库存表:
id
inv_type(FK of inventory_type.id)
inv_name, etc.
inventory_type 表:
id
type_name
我用 GROUP BY 做了简单的查询:
SELECT it.type_name AS [Inventory name], Count(i.ID) AS Quantity
FROM inventory_type AS it INNER JOIN inventory AS i ON it.ID = i.inv_type
GROUP BY it.type_name;
这个查询的结果是:
Inventory Name | Quantity
VideoCamera 3
PC 5
.....
但是结果应该是这样的:
Quantity | VideoCamera | PC
Quantity | 3 5
我试过这样做:
TRANSFORM Count(it.ID) AS Quantity
SELECT "Quantity"
FROM inventory_type AS it INNER JOIN inventory AS i ON it.ID = i.inv_type
GROUP BY it.type_name
PIVOT it.type_name;
但结果并不如我所愿:
Quantity | VideoCamera | PC
Quantity 3
Quantity 5
有人可以帮我解决这个问题吗,我真的无法理解 ms 访问语义。
【问题讨论】:
标签: sql ms-access ms-access-2013