我有以下SQL查询:
SELECT Sys.Name0, Sys.User_Name0, SF.FilePath, SF.Filename, Count(SF.FileName) AS FileCount, Sum(SF.FileSize / 1024 / 1024) AS 'Used Space'
FROM v_R_System Sys
INNER JOIN v_GS_SoftwareFile SF ON Sys.ResourceID = SF.ResourceID
WHERE SF.FilePath LIKE '%' + 'Users' + '%' + '%documents%'
AND SF.FileSize > 0
GROUP BY Sys.Name0, Sys.User_Name0, SF.Filename, SF.FilePath
HAVING Count(SF.FileName) > 0
ORDER BY Sys.Name0 DESC
问题是,我得到的信息太多了。我想排除记录而不计算FILENAME就像.exe,.dll,.ico这样的地方。
答案 0 :(得分:1)
如果您希望排除记录,可以将其添加到where子句:
AND RIGHT(FileName,4) NOT IN('.exe', '.dll', '.ico', 'etc.')
OR
AND Filename Not Like '%.exe' AND Filename Not Like '%.dll' AND Filename Not Like '%.ico' AND etc....
答案 1 :(得分:1)
使用此Where子句(假设SQL Server)
Where SF.FilePath like '%'+'Users'+'%' +'%documents%'
and SF.FileSize > 0
And FileName Not Like '%.exe'
And FileName Not Like '%.dll'
And FileName Not Like '%.ico'
这应该让你去....
答案 2 :(得分:0)
您可以将其添加到where子句作为额外条件。排除文件名:
AND RIGHT(FileName,4) NOT IN('.exe', '.dll', '.ico', 'etc.')
排除大于1mb的文件大小。
AND SF.FileSize > 1
完整陈述:
SELECT
Sys.Name0,
Sys.User_Name0,
SF.FilePath,
SF.Filename,
Count(SF.FileName) AS FileCount,
Sum(SF.FileSize / 1024 / 1024) AS 'Used Space'
FROM
v_R_System Sys
INNER JOIN v_GS_SoftwareFile SF ON Sys.ResourceID = SF.ResourceID
WHERE
SF.FilePath LIKE '%' + 'Users' + '%' + '%documents%'
AND SF.FileSize > 1
AND RIGHT(FileName,4) NOT IN('.exe', '.dll', '.ico', 'etc.')
GROUP BY Sys.Name0, Sys.User_Name0, SF.Filename, SF.FilePath
HAVING Count(SF.FileName) > 0
ORDER BY Sys.Name0 DESC