CSHTML/SQL SUM 一行
我知道在 mysql 中它的 SUM(size),但由于某种原因在 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 ]
I know in mysql its SUM(size), but for some reason building this in razor cshtml its not the same and i cant find anywhere that talks about adding or subtracting 2 numbers in cshtml. So what would be the right function to use to add up rows size?
Code:
@{
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>
Error:
Exception Details: System.Data.SqlServerCe.SqlCeException: The specified argument value for the
function is not valid. [ Argument # = 1,Name of function(if known) = SUM ]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只对每个表的
Count
感兴趣,那么您应该SELECT COUNT(*) FROM Shows
等等,而不是仅仅从每个表中提取所有数据算一下。SUM
仅适用于数字类型,例如int
、numeric
、money
和float
> 确保该列是表中的这些类型之一。If you're only interested in the
Count
of each table then you shouldSELECT COUNT(*) FROM Shows
and so forth rather than pulling all the data from each table just to get a count.SUM
only works with numeric types such asint
,numeric
,money
, andfloat
make sure that the column is one of those types in your table.