我有一个定义如下的表:
sym ="C""MS""MS""MS""IBM""IBM""C""C""C"$symbol;
price= 49.6 29.46 29.52 30.02 174.97 175.23 50.76 50.32 51.29;
qty = 2200 1900 2100 3200 6800 5400 1300 2500 8800;
timestamp = [09:34:07,09:36:42,09:36:51,09:36:59,09:32:47,09:35:26,09:34:16,09:34:26,09:38:12];
t1 = table(timestamp, sym, qty, price);
那么 t1 中的数据为
我想计算每家公司的股票收益,并得到如下结果,
sym timestamp price ret
--- --------- ------ ---------
C 09:34:07 49.6
C 09:34:16 50.76 0.023387
C 09:34:26 50.32 -0.008668
C 09:38:12 51.29 0.019277
IBM 09:32:47 174.97
IBM 09:35:26 175.23 0.001486
MS 09:36:42 29.46
MS 09:36:51 29.52 0.002037
MS 09:36:59 30.02 0.016938
如何编写满足需求的 SQL 语句?