在previous question我得到了这个结果:
WITH ItemCount
AS ( SELECT BrandId
,COUNT(Items.ITEMNO) AS item_Count
FROM Items
,Brand_Products
,Brands
WHERE Items.ITEMNO = Brand_Products.ItemNo
AND Brands.BrandId = Brand_Products.BrandId
AND Items.SubcategoryID = 'SCat-020'
GROUP BY Brands.BrandId)
SELECT b.BrandName + ' ' + CONVERT(VARCHAR(5), Item_Count)
FROM Brands AS b
JOIN ItemCount AS I
ON b.BrandId = i.BrandId
我想要添加的是选择连接字符串和BrandId。
答案 0 :(得分:1)
除非这是某种技巧问题,否则您只需将其添加到SELECT
列表中:
SELECT b.BrandId, b.BrandName + ' ' + CONVERT(VARCHAR(5), Item_Count)
FROM Brands AS b
JOIN ItemCount AS I
ON b.BrandId = i.BrandId