- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
到目前为止我所拥有的:http://sqlfiddle.com/#!2/bbfec/6
我想获取给定公司可出售的给定股票的股票数量 - 按价格分组。例如,对于公司号 9 和股票号 1,我想要这样的数据:
| id | name | price | date | quantity | total |
------------------------------------------------------------------
| 3 | ALTR | 2.240 | 2015-05-12 04:29:29 | 50 | 112.00 |
| 7 | ALTR | 2.449 | 2014-06-10 18:21:02 | 50 | 122.45 |
因为公司9在2015-05-12 04:29:29买入200只股票,在2014-06-10 15:50:17卖出100只股票,在2014-06-10 17:06:18又买入50只股票2014-06-10 18:21:02 50。
我不需要所有股票的总数,因为当公司收购它们时,它们的价格不同。价格和日期是采购价格和日期,但数量是某次采购剩余的数量。
提前致谢。
草莓,想要的结果:
| id | price | date | quantity |
-----------------------------------------------
| 3 | 2.240 | 12-05-2015 | 50 |
| 7 | 2.449 | 10-06-2014 | 50 |
最佳答案
开头:
select id_acao, id_empresa, ifnull(bought,0) - ifnull(sold,0) as stock
from
(
select id_acao, id_empresa,
(select sum(quantidade) from acao_trans where tipo='C' and id_acao=a.id_acao and id_empresa=a.id_empresa) as bought,
(select sum(quantidade) from acao_trans where tipo='V' and id_acao=a.id_acao and id_empresa=a.id_empresa) as sold
from acao_trans a group by id_acao,id_empresa
) x
;
+---------+------------+-------+
| id_acao | id_empresa | stock |
+---------+------------+-------+
| 1 | 4 | 1500 |
| 1 | 9 | 100 |
| 8 | 9 | 3500 |
| 13 | 9 | 5000 |
+---------+------------+-------+
并将此查询加入到您的基本 acao 和 empresa 表中。
备注:出于统计等目的,使用负数量进行销售交易会比交易类型“C”和“V”更容易。
关于mysql - 获取可供出售的股票,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24160978/
Windows Phone 8 上的开发人员可以使用两个命名空间 - Microsoft.Devices.Sensors 和 Windows.Devices.Sensors。它们几乎完全相同。有人能解
如何使 NameValueCollection 可供 LINQ 查询运算符(例如 where、join、groupby)访问? 我尝试了以下方法: private NameValueCollectio
我希望能够测试哪些文本转语音可供我的 iOS 应用程序与 AVSpeechSynthesis 一起使用。生成已安装声音的列表很容易,但 Apple 将其中一些声音禁止应用程序使用,我想知道哪些声音。
我让 postgres.app 在我的 Mac 上本地运行,并希望我的本地 docker 容器能够连接到它。我该如何最好地做到这一点? 我发现这篇文章建议使用 --add-host 标志(Host p
我有一个包含多个 HTML 文件的文件夹。每个 HTML 文件都使用 AngularJS 并包含相同的声明,如下所示;
与仍然生活在 ant 构建环境世界(在 Windows 机器上)的客户合作。想要在 Java 程序中使用 google-cloud-translate 库,但如果我包含 google-cloud-tr
我是一名优秀的程序员,十分优秀!