我遇到了一些关于存储过程的问题,我编写了一个存储,我需要拍摄三列产品,如下所示
SELECT
Count([TPDTN].[ProductName]) as 'Product Count',
[TPDTN].[CategoryID]
FROM
[TPDTN]
LEFT JOIN
[TPDCN] ON [TPDTN].[CategoryID] = [TPDCN].[libDocumentID]
GROUP BY
[TPDTN].[CategoryID], [TPDCN].[libDocumentID]它显示的结果如下:
Product Count CategoryID
---------------------------
2 1
9 2
2 3
2 4
1 5但我不知道该怎么表现
Product Count CategoryID libDocumentID
-----------------------------------------------
2 1 123456789
9 2 123456789
2 3 123456789
2 4 123456789
1 5 123456789生产者ID (LibdocumentID)来自其他表,但当我使用SELECT [TPDCN].[libDocumentID]时,其值为NULL
Product Count CategoryID libDocumentID
------------------------------------------------
2 1 NULL
9 2 NULL
2 3 NULL
2 4 NULL
1 5 NULL我该怎么解决它呢?谢谢
发布于 2014-03-12 11:42:45
只需将其添加到select中,如果不需要NULL,则需要一个内部联接:
SELECT Count([TPDTN].[ProductName]) as 'Product Count',[TPDTN].[CategoryID], [TPDCN].[libDocumentID]
FROM [TPDTN]
inner join [TPDCN]
ON [TPDTN].[CategoryID] = [TPDCN].[libDocumentID]
GROUP BY [TPDTN].[CategoryID],[TPDCN].[libDocumentID]https://stackoverflow.com/questions/22341502
复制相似问题