我在MSSQL中有一个SQL VIEW,我使用VBA从Excel查询。我感兴趣的两个栏目如下。在我的GROUP BY位置代码和描述之后,有时我将获得重复的位置代码,这非常好。如何在GROUP BY之后获得一个给出COUNT重复数的列?在下面的例子中,两个PB-SCHOOL在新列中将有2个,其余的将有1个。
这是我的代码:
SELECT LOCCODE as [Location Code], LOCATION as [Location Description]
FROM dbo.View_PendingAnalytes
WHERE (COLDATE > DateAdd(Day, -90, GETDATE()))
GROUP BY LOCCODE, LOCATION
这是输出:
Location Code |Location Description
----------------|---------------------------
LSCAKE-503 |La Salina press cake
MISSION |Mission Linen Service
OOOCOMP |Outfall composite
PB-SCHOOL |123 Nowhere (BW TEST)
PB-SCHOOL |456 Nowhere (BW TEST)
SABRA |Sabra Dipping Co.
SLCAKE-503 |San Luis Rey centrifuge cake
SLRCLAIM |SLR Reclaim Comp
感谢。