我有一个名为tbl_upload的表,它将上传文件的数据存储到其中,其中包含Filename,filetype,filesize,serial等列。
| 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&#中需要其数据源39;类型。 所以我需要获得总的no.of doc文件,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
这是一个好方法还是有比这更好的方法?我只想要完全没有。每种文件类型......
答案 0 :(得分:3)
为什么不尝试将结果放在表格中,然后在客户端中将它们添加到变量中。
SELECT Filetype,
COUNT(*) AS TypeCount
FROM tbl_Uploads
GROUP BY Filetype