我有一个名为tbl_upload的表,它将上传文件的数据存储到其中,其中包含文件名、文件类型、文件大小、串行等列。
| FileName|Filetype|Filesize|Serial|
| a | doc | 1232 | 1 |
| b | txt | 1232 | 2 |
| c | pdf | 321 | 4 |
| d | xls | 41 | 5 |
| e | rtf | 23 | 6 |就像这样……
可能有8-10个文件类型,包括odt、html、xml等.
在页面上,我想使用jqxChart显示图表中的所有类型,这需要它的数据源以‘json’、‘array’或'xml‘类型。所以我需要得到总no.of文档文件,总no.of txt文件,no.of rtf等等。我写了一个SP
ALTER proc [dbo].[GetFiles] @Pdf int out, @doc int out, @odt int out, @txt int out
as
begin
select @Pdf= COUNT (*) from tbl_Uploads where Filetype='xml'
select @doc=COUNT (*) from tbl_Uploads where Filetype='doc'
select @txt=COUNT (*) from tbl_Uploads where Filetype='txt'
select @odt=COUNT (*) from tbl_Uploads where Filetype='odt'
...so on
end这是一个好方法,还是有比这更好的方法?我只想要完全不。每种文件类型..。
发布于 2014-08-01 12:33:57
为什么不尝试在表中获得结果,然后在客户端将它们添加到变量中。
SELECT Filetype,
COUNT(*) AS TypeCount
FROM tbl_Uploads
GROUP BY Filetypehttps://stackoverflow.com/questions/25080359
复制相似问题