不太清楚如何给这个标题,但我尽我所能。我有一份报告,其中显示了选定位置的所有资产。我们的问题之一是我们将一切都视为资产。因此,一个典型的计算机系统将有 5 台计算机、8 台显示器,但有 10 多根网线。我正在尝试编写一份报告,该报告将“汇总”任何不必要的项目并显示计数而不是实际项目。
例如,我想要这样:
Desc | Manufacturer | Serial Number
-----+------- ----+--------------------
20" monitor | Dell | 123456
25" monitor | Dell | 123456ab
6ft Net. Cable | N/A | NA123
6ft Net. Cable | N/A | NA124
6ft Net. Cable | N/A | NA125
6ft Net. Cable | N/A | NA456
1TB SATA HD | SeaGate | SG125000
1.5TB SATA HD | SeaGate | SG100000
成为:
Desc | Manufacturer | Serial Number/Qnty
-----+------- ----+-----------------------------
20" monitor | Dell | 123456
25" monitor | Dell | 123456ab
6ft Net. Cable | N/A | 4
1TB SATA HD | SeaGate | SG125000
1.5TB SATA HD | SeaGate | SG100000
这是我的 SQL,它让我获得最高部分,但我不太确定从哪里开始获得最低结果。
SELECT i.ItemDescription AS Desc, s.Name AS Manufacturer, inv.SerialNumber AS [Serial Number]
FROM Assets a
LEFT OUTER JOIN Inventory inv ON a.InventoryID = inv.InventoryID
LEFT OUTER JOIN Items i ON inv.ItemID = i.ItemID
LEFT OUTER JOIN Rooms r ON a.RoomID = r.RoomID
LEFT OUTER JOIN Locations l ON r.LocationID = l.LocationID
LEFT OUTER JOIN Suppliers s ON i.ManufacturerID = s.SupplierID
WHERE l.LocationID = 5
我需要让“分组”行基于标准,所以它必须在 WHERE 子句中,比如:
WHERE l.LocationID = 5 AND inv.SerialNumber LIKE 'NA%'
但我不太确定把它放在哪里,所以它不会过滤我所有的记录序列号如“NA%”的那些
任何帮助是极大的赞赏!