免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1441 | 回复: 1
打印 上一主题 下一主题

问一个存储过程和视图方面的问题。。。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-01 12:15 |只看该作者 |倒序浏览
现在我有一个表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,继续往下计算。。。



请问能够怎样实现?谢谢

论坛徽章:
0
2 [报告]
发表于 2009-04-02 18:34 |只看该作者
在sql中加入条件就行
具体请阅读mysql help
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP