我想知道是否有人可以帮我构建一个查询或php代码,给定下表可以在列#34生成输出;所需的输出"。
基本上,查询或php代码需要按符号汇总financialvol col并在每次计算时或openposition为0时显示结果。
tid | time | symbol | openposition | financialvol | desired output
87646 | 10:29:38 | CTIP3 | 400 | 8744.00 |
87645 | 10:29:47 | CTIP3 | 800 | 8732.00 |
87644 | 10:29:52 | CTIP3 | 1000 | 4366.00 |
87643 | 10:30:02 | CTIP3 | 1200 | 4368.00 |
87642 | 10:30:06 | CTIP3 | 1400 | 4364.00 |
87639 | 10:31:57 | CTIP3 | 1200 | -4382.00 |
87638 | 10:32:04 | CTIP3 | 1000 | -4372.00 |
87637 | 10:32:08 | CTIP3 | 800 | -4362.00 |
87636 | 10:32:14 | CTIP3 | 600 | -4388.00 |
87635 | 10:32:40 | CTIP3 | 0 | -13098.00 | -28
87647 | 10:28:54 | PCAR4 | 400 | 40480.00 |
87641 | 10:31:30 | PCAR4 | 200 | -20246.00 |
87640 | 10:31:41 | PCAR4 | 0 | -20340.00 | -106
87651 | 10:27:42 | TIMP3 | 1500 | 12345.00 |
87650 | 10:27:48 | TIMP3 | 11500 | 82300.00 |
87649 | 10:28:09 | TIMP3 | 1500 | -82600.00 |
87648 | 10:28:23 | TIMP3 | 0 | -12345.00 | -300
87657 | 10:26:44 | VIVT4 | -500 | -23710.00 |
87656 | 10:26:53 | VIVT4 | 0 | 23700.00 | -10
87655 | 10:26:59 | VIVT4 | -500 | -23740.00 |
87653 | 10:27:00 | VIVT4 | -1000 | -23740.00 |
87654 | 10:27:00 | VIVT4 | -1500 | -23740.00 |
87652 | 10:27:24 | VIVT4 | 0 | 71055.00 | -175
感谢大家的观察和尝试!
答案 0 :(得分:0)
我相信你正在寻找像this这样的东西。
为了使这一点有意义,您需要将表格排序为:order by time asc
答案 1 :(得分:0)
SELECT x.*
, CASE WHEN x.openposition = 0 THEN SUM(y.financialvol) ELSE '' END desired
FROM my_table x
JOIN my_table y
ON y.symbol = x.symbol AND y.time <= x.time
GROUP
BY x.symbol, x.time;