Sql 显示带有连接字段的其他字段
在一次实验中,我得到了这个结果:Sql 显示带有连接字段的其他字段,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,在一次实验中,我得到了这个结果: WITH ItemCount AS ( SELECT BrandId ,COUNT(Items.ITEMNO) AS item_Count FROM Items ,Brand_Products ,Brands WHERE Items.ITEMNO = Brand_Products.ItemNo
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。除非这是一个技巧性问题,否则您只需将其添加到
选择列表中:
SELECT b.BrandId, b.BrandName + ' ' + CONVERT(VARCHAR(5), Item_Count)
FROM Brands AS b
JOIN ItemCount AS I
ON b.BrandId = i.BrandId
@萨米拉,我很高兴能帮上忙!