第二关
小明今年初入股市,请帮忙计算他今年的收益
建表
create table stocks (
code varchar(6) not null,
operation varchar(10),
date varchar(10),
price float,
amount int
)
code 表示股票代码,operation为buy/sell,表示买入卖出,date表示时间,price表示价格,amount表示数量。
插入数据
insert into stocks values
('512010', 'buy', '2022-01-19', 0.587, 1000),
('512888', 'buy', '2022-01-19', 7.01, 2000),
('600544', 'buy', '2022-01-19', 17.24, 100),
('512888', 'sell', '2022-02-01', 5.88, 2000),
('600544', 'buy', '2022-02-04', 15.68, 100),
('600544', 'sell', '2022-02-11', 17.35, 200),
('512888', 'buy', '2022-02-14', 7.55, 2000),
('512010', 'buy', '2022-03-22', 0.511, 1000),
('512888', 'sell', '2022-05-01', 6.02, 2000),
('512010', 'buy', '2022-06-11', 0.499, 1000),
('512010', 'buy', '2022-07-29', 0.488, 1000),
('512010', 'sell', '2022-10-11', 0.428, 4000);
要求输出:
盈亏
-------
-5515
(1 row)
本关参与方式
活动期间10月19日-10月24日,只要在论坛活动帖(地址:community.memfiredb.com/topic/218/%… Cloud SQL编辑器中的效果),然后带着自己的答案找管理员核兑抽奖机会哦~
🌟 本题为闭卷模式,被公开的答案有成绩作废的风险哦~