从表中的所有行计算总金额总金额

由网友(三岁就可萌了)分享简介:你能帮帮我吗?我想计算我的价格表中所有行的总,但绝不值加起来,现在它似乎不计算了两种。Can you please help me with this? I am trying to calculate the total of all the rows in my Price Table, but the valu...

你能帮帮我吗?我想计算我的价格表中所有行的总,但绝不值加起来,现在它似乎不计算了两种。

Can you please help me with this? I am trying to calculate the total of all the rows in my Price Table, but the values never add up, and now it doesn't seem to calculate anymore either.

我有以下几点:

@{
    decimal money = 0.00m;
    var prices = "SELECT Price, SUM(Price) FROM PriceTable GROUP BY Price";

            var database = Database.Open("MYDB");
            database.QuerySingle(prices);
            money = prices.AsDecimal();
}

和地方在我的HTML I型:

And somewhere in my HTML I type:

@money // to display the totalAmount

我这样做对吗?我搜索了这一点,但令人惊讶的似乎有关于这个没有太多的信息,我可能没有使用正确的关键字,但。

Am I doing it right? I've searched for this, but surprisingly there seems to be not much info about this, I'm probably not using the right keywords though.

感谢您

推荐答案

变更

var prices = "SELECT Price, SUM(Price) FROM PriceTable GROUP BY Price";

var prices = "SELECT SUM(Price) FROM PriceTable";

如果你想要的是所有行的总和,不需要进行分组。

IF all you want is the sum of all rows, the grouping is not required.

也;

var result = database.QuerySingle(prices);
money = Convert.ToDecimal(result);
阅读全文

相关推荐

最新文章