sql查询,通配符,MS sql SERVER 2005

时间:2021-09-26 16:28:49

I need my query to pull all DirName's what have the following prefix 'site/test/test/' is the correct syntax a '*'

我需要我的查询来拉出所有的DirName它有以下前缀'site/test/ '是正确的语法a '*'

SELECT  DirName, count(*) AS FileCount, SUM(Size)/1024 as 'SizeKB' 
FROM  alldocs
Where DirName = 'site/test/test/*'
GROUP BY  dirName 
ORDER BY DirName

2 个解决方案

#1


5  

You need to use SQL's LIKE clause:

您需要使用SQL的LIKE子句:

SELECT  DirName, count(*) AS FileCount, SUM(Size)/1024 as 'SizeKB' 
FROM  alldocs
Where DirName LIKE 'site/test/test/%'
GROUP BY  dirName 
ORDER BY DirName

See http://www.sql-tutorial.net/SQL-LIKE.asp

参见http://www.sql-tutorial.net/SQL-LIKE.asp

#2


0  

Are you using MySQL? If you are, you can use LEFT in something like

你使用MySQL吗?如果你是,你可以用LEFT

SELECT  DirName, count(*) AS FileCount, SUM(Size)/1024 as 'SizeKB' 
FROM  alldocs
Where LEFT( DirName, LENGTH( 'site/test/test/' ) ) = 'site/test/test/'
GROUP BY  dirName 
ORDER BY DirName

#1


5  

You need to use SQL's LIKE clause:

您需要使用SQL的LIKE子句:

SELECT  DirName, count(*) AS FileCount, SUM(Size)/1024 as 'SizeKB' 
FROM  alldocs
Where DirName LIKE 'site/test/test/%'
GROUP BY  dirName 
ORDER BY DirName

See http://www.sql-tutorial.net/SQL-LIKE.asp

参见http://www.sql-tutorial.net/SQL-LIKE.asp

#2


0  

Are you using MySQL? If you are, you can use LEFT in something like

你使用MySQL吗?如果你是,你可以用LEFT

SELECT  DirName, count(*) AS FileCount, SUM(Size)/1024 as 'SizeKB' 
FROM  alldocs
Where LEFT( DirName, LENGTH( 'site/test/test/' ) ) = 'site/test/test/'
GROUP BY  dirName 
ORDER BY DirName