我在mysql中知道它的SUM(大小),但由于某些原因在razor cshtml中构建它不一样,我无法找到任何谈论在cshtml中添加或减去2个数字的地方。那么用于添加行大小的正确函数是什么?
代码:
@{
Page.Title = "Home @";
var PageTitle = "Home";
var db = Database.Open("PhotoGallery");
var shows = db.Query(@"SELECT * FROM Shows").ToList();
var seasons = db.Query(@"SELECT * FROM Seasons").ToList();
var episodes = db.Query(@"SELECT * FROM Episodes").ToList();
var comics = db.Query(@"SELECT * FROM Comics").ToList();
var artists = db.Query(@"SELECT * FROM Artists").ToList();
var albums = db.Query(@"SELECT * FROM Albums").ToList();
var comicsize = db.Query(@"SELECT SUM(size) FROM Comics").ToList();
var totalsizeb = comicsize;
}
<h1>@PageTitle</h1>
<p align="center">
@shows.Count TV Shows | @seasons.Count Seasons | @episodes.Count Episodes | @comics.Count Comics | @artists.Count Artists | @albums.Count Albums<br />
Bytes | MB | GB | TB
</p>
错误:
Exception Details: System.Data.SqlServerCe.SqlCeException: The specified argument value for the
function is not valid. [ Argument # = 1,Name of function(if known) = SUM ]
答案 0 :(得分:1)
如果您只对每个表的Count
感兴趣,那么您应该SELECT COUNT(*) FROM Shows
,而不是从每个表中提取所有数据,只是为了获得计数。
@{
Page.Title = "Home @";
var PageTitle = "Home";
var db = Database.Open("PhotoGallery");
var shows = (int)db.QueryValue(@"SELECT Count(*) FROM Shows");
var seasons = (int)db.QueryValue(@"SELECT Count(*) FROM Seasons");
var episodes = (int)db.QueryValue(@"SELECT Count(*) FROM Episodes");
var comics = (int)db.QueryValue(@"SELECT Count(*) FROM Comics");
var artists = (int)db.QueryValue(@"SELECT Count(*) FROM Artists");
var albums = (int)db.QueryValue(@"SELECT Count(*) FROM Albums");
var comicsize = (int)db.QueryValue(@"SELECT SUM(size) FROM Comics");
var totalsizeb = comicsize;
}
<h1>@PageTitle</h1>
<p align="center">
@shows TV Shows | @seasons Seasons | @episodes Episodes | @comics Comics | @artists Artists | @albums Albums<br />
Bytes | MB | GB | TB
</p>
SUM
仅适用于int
,numeric
,money
和float
等数字类型,请确保该列属于以下类型之一你的桌子。