我有一张像下面这样的桌子
CREATE TABLE [dbo].[MyTable](
[MyTableID] [int] IDENTITY(1,1) NOT NULL,
[ContainerID] [int] NOT NULL,
[FIELD_A] [nvarchar](15) NOT NULL,
[FIELD_B] [nvarchar](15) NOT NULL,
[FIELD_C] [nvarchar](15) NOT NULL,
[FIELD_D] [nvarchar](50) NULL,
CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED ( [MyTableID] ASC )
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
简单来说,FIELD_A
和FIELD_B
由分组。FIELD_C
FIELD_D
ContainerID
考虑到每个容器包含大约 2k 条记录,我想执行一个返回两个ContainerID
. 例如,在比较容器 1 和容器 2 时,我需要知道:
- 1 中存在多少条记录,2 中没有,反之亦然
- 两个容器中存在多少条记录
获得这些结果的最简单方法是什么?谢谢!