从表中的所有行计算总金额 [英] Calculate TotalAmount from all Rows in Table

查看:194
本文介绍了从表中的所有行计算总金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

这篇关于从表中的所有行计算总金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆