- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我得到了一个包含事务的 2 列表,其中存储了更改时间 (unix_time) 和更改值。
create table transactions (
changed int(11),
points int(11)
);
insert into transactions values (UNIX_TIMESTAMP('2014-03-27 03:00:00'), +100);
insert into transactions values (UNIX_TIMESTAMP('2014-05-02 03:00:00'), +100);
insert into transactions values (UNIX_TIMESTAMP('2015-01-01 03:00:00'), -100);
insert into transactions values (UNIX_TIMESTAMP('2015-05-01 03:00:00'), +150);
要获得当前余额,您需要对所有值求和,而要获得过去的余额,如果该值的更改时间少于请求的时间,则需要求和,如下所示:
select
sum(case when changed < unix_timestamp('2013-12-01') then
points
else
0
end) as cash_balance_2013_11,
...
因此每个月都需要有一个单独的 SQL 代码。我想要 SQL 代码来为我提供所有月份的余额。 (例如从固定日期到现在)
编辑:
最佳答案
您可以只分组依据
和按
月份排序吗?
更新:要获得运行总计,您必须将各个月份加入到一组按月总计中,匹配“小于或等于”:-
select
m.single_month
, sum(month_of_change.total_points) as running total_by_month
from
(
select
sum(points) as total_points
, month_of_change
from
(
select
points
, MONTH(FROM_UNIXTIME(t.time_of_change)) as month_of_change -- assumes unix_time
from mytable t
) x
group by month_of_change
) monthly_totals
inner join
(
select distinct MONTH(FROM_UNIXTIME(t.time_of_change)) as single_month
) m
on monthly_totals.month_of_change <= m.single_month
group by m.single_month
(注意:未测试)
关于mysql - 获取每个月的交易余额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27046772/
这可能是一个简单的问题,但我无法弄清楚。 我有两个表中的数据 - 1)贷款 2)还款。我被要求制作一份报告,根据我们当前的投资组合计算每个季度的预期余额。 所以我采取的方法是取贷款表中所有余额的总和(
每次登录时,我都会从 MySQL 数据库获取 $_SESSION[balance] 的值。如何更新客户端浏览器中的值而不每 5 分钟重新加载页面?我认为可以使用 AJAX 来完成? 抱歉,如果这太模糊
我有一个 MySQL 金融交易表。 表格是这样的: +----+-----------+--------+--------+---------+---------+ | id | member_id
我正在开发一个桌面软件,它向用户每次执行主要操作收费。例如,每个 PDF 打印将向用户收取 0.1 美元的费用。 我的软件提供多线程。 . 所以,如果它运行单线程,它就可以正常工作:) 但问题是如果用
嗨,我正在尝试找出应该使用什么 SQL 语句来生成此输出。我尽了最大努力,但我的查询不起作用。谢谢 STUDNO | DEBIT | CREDIT | BALANCE 1001 | 1000
我有下表并需要获得以下输出。 +---------+-----------+------+----------+------------+ | item_id | item_name | qty |
我正在尝试在类里面使用一种收费的方法。方法是这样的: public double chargeFee() { balance -= 10; return balance;
我正在尝试让我的钱包地址余额呈现在我的前端。这是我目前所拥有的。 const [balance, setBalance] = useState(""); const handleWalletBalan
我们正在将 Facebook Credits 实现为 Facebook 上的虚拟货币。 我们已经申请并被列入白名单以访问 Facebook Credits 余额方法,但是从我能够找到的小文档(主要是论
有谁知道如何在 Twilio 中以编程方式检查帐户余额(通过 API)?没有实现吗? 最佳答案 您可以获得Twilio Account details然后使用 请求获取余额subresource_ur
我已经在 PayPal 文档中搜索了两个小时,但找不到答案,甚至搜索了 Google。 在这里检查: https://developer.paypal.com/docs/api/#api-operat
免责声明:我知道这个问题已经被问过很多次了,但我想要的只是一个替代方案。 表格如下: create table Account (Name varchar(20), TType varchar(5)
我需要更正和转换一个函数,检查 btc 余额的 2 个地址,例如(addr 和 addr1),返回的是 json 值,我需要指定我不太了解 golang..需要帮助! func balance(add
当我运行它时,我得到“TypeError:无法读取未定义的属性‘balance’。”我刚开始学习 Node,我不确定自己做错了什么。请帮忙。 跟作用域有关系吗?我该如何解决? //create an
以下 Vanilla JS 示例通过 Phantom 钱包连接到 Solana 区 block 链并断开连接。 连接成功并获取公共(public)地址。 尝试使用 JSON-RPC 请求获取钱包余额和
我是一名优秀的程序员,十分优秀!