Mysql 累积投资组合摘要
我在mysql中有两个表。所有日期均为yyyy-mm-dd。如果有人了解共同基金,这个问题就会清楚Mysql 累积投资组合摘要,mysql,Mysql,我在mysql中有两个表。所有日期均为yyyy-mm-dd。如果有人了解共同基金,这个问题就会清楚 NAVMaster-存储方案的NAV。除节假日和周末外,导航每天都在变化 事务-存储用户完成的事务。当用户购买金额为purchamount的方案时。他将根据交易日的资产净值(Purchamount/NAV=单位)分配单位 我需要展示用户投资每天的变化。价值按(累计单位余额)*(当日资产净值)计算 例如: 2020年1月1日,用户在方案2中投资1000英镑,在方案2中投资1000英镑 方案一。他在每
谢谢这是我的东西。我认为它更接近你想要的,但它并没有给出与你所拥有的相同的答案。您如何知道方案2 1/6的导航
select
trdate,
invested,
sum(holding) value
from
(
select
trdate,
(
select
sum(purchamount)
from
transactions
where
trdate <= t2.trdate
)
invested,
schemecode,
(
select
nav
from
transactions
where
trdate = t2.trdate
and schemecode = t2.schemecode
)
* (
select
sum(units)
from
transactions
where
trdate <= t2.trdate
and schemecode = t2.schemecode) holding
from
transactions t2
)
t1
group by
trdate
这是我的。我认为它更接近你想要的,但它并没有给出与你所拥有的相同的答案。您如何知道方案2 1/6的导航
select
trdate,
invested,
sum(holding) value
from
(
select
trdate,
(
select
sum(purchamount)
from
transactions
where
trdate <= t2.trdate
)
invested,
schemecode,
(
select
nav
from
transactions
where
trdate = t2.trdate
and schemecode = t2.schemecode
)
* (
select
sum(units)
from
transactions
where
trdate <= t2.trdate
and schemecode = t2.schemecode) holding
from
transactions t2
)
t1
group by
trdate
请格式化您的帖子字符串。这太难辨认了。:)一般来说,在这个论坛上获得答案的最好方法是发布以下内容:(1)你有什么数据;(2) 你想要什么数据;(3) 你试过的。那么,您应该如何呈现数据呢?最好的做法是制作一个提琴,这样我们就可以编辑它(考虑一下),其次是发布SQL命令,这样我们就可以在本地机器上重新创建数据。在那之后,试着在整洁的表格中发布,这样我们可以剪切和粘贴。而且,很难计算出应该是什么。你能用文字解释一下吗?很抱歉,我不能正确地设置问题的格式。我已经为你做了一个小提琴。请设置你的帖子字符串的格式。这太难辨认了。:)一般来说,在这个论坛上获得答案的最好方法是发布以下内容:(1)你有什么数据;(2) 你想要什么数据;(3) 你试过的。那么,您应该如何呈现数据呢?最好的做法是制作一个提琴,这样我们就可以编辑它(考虑一下),其次是发布SQL命令,这样我们就可以在本地机器上重新创建数据。在那之后,试着在整洁的表格中发布,这样我们可以剪切和粘贴。而且,很难计算出应该是什么。你能用语言解释一下吗?很抱歉,我不能正确地编排问题的格式。我为你做了一把小提琴。很高兴我能帮忙。你能为将来的用户将答案标记为正确吗?太好了。很高兴我能帮忙。你能为将来的用户将答案标记为正确吗?
+----------------------+-----------+
| date | invested | value |
+----------------------+-----------+--------+
| 2020-01-01 | 2000 | 2000 |
| 2020-01-02 | 3980 | 4180 |
| 2020-01-03(Holiday) | 3980 | 4180 |
| 2020-01-04(Holiday) | 3980 | 4180 |
| 2020-01-05(Holiday) | 3980 | 4180 |
| 2020-01-06 | 6980 | 12500 |
+----------------------+-----------+--------+
select a.navdate, sum(b.units) as cumulative_sales
from navmaster a join transactions b on a.navdate >= b.trdate and a.schemecode=b.schemecode
group by a.navdate order by a.navdate
select
trdate,
invested,
sum(holding) value
from
(
select
trdate,
(
select
sum(purchamount)
from
transactions
where
trdate <= t2.trdate
)
invested,
schemecode,
(
select
nav
from
transactions
where
trdate = t2.trdate
and schemecode = t2.schemecode
)
* (
select
sum(units)
from
transactions
where
trdate <= t2.trdate
and schemecode = t2.schemecode) holding
from
transactions t2
)
t1
group by
trdate
trdate invested value
2020-01-01T00:00:00Z 2000 2000
2020-01-02T00:00:00Z 3980 4180
2020-01-06T00:00:00Z 6980 8000