Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 显示带有连接字段的其他字段_Sql_Sql Server_Sql Server 2008 - Fatal编程技术网

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

@萨米拉,我很高兴能帮上忙!