现在我有一个表daily_price_1994,
"date","ticker","right_price","volume","total","market_cap"
"19940103","000001",72.8569,308200,269417899,5900251988.1
"19940104","000001",72.8569,215200,269417899,5900251988.1
"19940105","000001",72.5242,315900,269417899,5873310198.2
"19940103","000002",73.8549,440700,269417899,5981077357.8
"19940104","000002",73.1895,599600,269417899,5927193778
"19940115","000002",73.5221,470200,269417899,5954135567.9
现在希望生成一个视图,添加一列num,变成如下的形式
"num","date","ticker","right_price","volume","total","market_cap"
1,"19940103","000001",72.8569,308200,269417899,5900251988.1
2,"19940104","000001",72.8569,215200,269417899,5900251988.1
3,"19940105","000001",72.5242,315900,269417899,5873310198.2
1,"19940103","000002",73.8549,440700,269417899,5981077357.8
2,"19940104","000002",73.1895,599600,269417899,5927193778
3,"19940115","000002",73.5221,470200,269417899,5954135567.9
其中num这列需要满足如下条件:
如果遇到第一行ticker = '000001'的情况,则第一个num是1,第二个是2。。。直到第五个为5,从第六个开始又变成1,第七个为2>.......一直下去
如果ticker的值改变了,如从第一个'000002'开始,按照上面的规则,把第一个num变为1,继续往下计算。。。
请问能够怎样实现?谢谢 |