如何在我选择的SQL Server中添加'%'

时间:2016-07-30 20:38:03

标签: sql sql-server select count

我想得到一张桌子的数量,我也希望显示GeoID的列表。问题是我无法在我的

中添加'%'
SELECT        
    GeoTitle AS Expr1,GeoId , (GeoId+'%') as moh,
    (SELECT       
         COUNT(Product.ProductId)
     FROM            
         Company 
     INNER JOIN
         Product ON Company.CompanyId = Product.CompanyId
     WHERE         
         (Company.GeoId LIKE moh)
    )
FROM            
    GeoLanguage
WHERE        
    (LanguageId = 1)

错误:

  

列名称'moh'无效。

1 个答案:

答案 0 :(得分:1)

试试这个

SELECT        A.GeoTitle AS Expr1,A.GeoId,
    (SELECT       count( Product.ProductId)
    FROM            Company INNER JOIN
                             Product ON Company.CompanyId = Product.CompanyId
    WHERE        (Company.GeoId LIKE A.GeoId+'%'))

    FROM            GeoLanguage as A
    WHERE        (A.LanguageId = 1)