本人在做一个网站系统的时候要用到存储过程,由于mssql和mysql的存储过程语句差别别较大,在网上查了很久也没有查出过所以然,所以求一个mysql的存储过程语句。要求如下:
我创建了一个数据库的视图,创建一个存储过程要用到视图中的查询字段。视图代码如下:
-- ----------------------------
-- View structure for `teacher_article_view`
-- ----------------------------
DROP VIEW IF EXISTS `teacher_article_view`;
CREATE VIEW `teacher_article_view` 
AS 
select 
`teachersinfo`.`cteachNo` AS `cteachNo`,
`teachersinfo`.`ctrueName` AS `ctrueName`,
`teachersinfo`.`csexual` AS `csexual`,
`schooltables`.`vschName` AS `vschName`,
`articleinfo`.`cartNo` AS `cartNo`,`articleinfo`.
`vartName` AS `vartName`,
`articleinfo`.`vartType` AS `varttype`,
`articleInfo`.`dpubtime` as `dpubtime`,
(`rateresult`.`iResultScore` / `articlepartner`.`irank`) AS `artiScore` 
from 
((((`articlepartner` join `rateresult`) join `articleinfo`) join `teachersinfo`) join `schooltables`) 
where 
((`articleinfo`.`cartNo` = `articlepartner`.`cartNo`) and (`teachersinfo`.`cteachNo` = `articlepartner`.`cteachNo`) 
and (`articlepartner`.`cResultNo` = `rateresult`.`cResultNo`) and (`teachersinfo`.`cschNo` = `schooltables`.`cschNo`));我想统计得出上面视图中 'artiScore' 的总和,条件是根据 'cteachNo' 来统计和 'dpubtime' 的一个时间段以内。
这个存储过程用到的变量如下:
@cteachNo char(6)
@Begin date
@End date
sql查询语句如下:
select sum(artiScore) as articleSumScore from teacher_article_view where cteachNo=@cteachNo and (dpubtime >@Begin and dpubTime <           @End)
根据以上信息,求一个mysql的存储过程语句。万分感谢。

解决方案 »

  1.   

    没看懂你的需求和问题是什么?能否举例说明。
    建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  2.   

    这样吧,我用mysql语句把这个存储过程语句写出来,改成mysql语句的存储过程,
    mssql的语句如下,条件和视图看一楼:create procedure prcGetArticleSumScore @cteachNo char(6),@Begin datetime,@End datetime 
    as
    select sum(artiScore) as "artiSumScore" from teacher_article_view
    where cteachNo = @cteachNo and (dpubtime > @Begin and dpubtime < @End )这样不知道写清楚了没有,也不知道写正确了没有,存储过程平时很少用,以前学的都忘了。管他的了。
      

  3.   

    哦哦,我忘了,在网上看到说 mysql 5.0 以前的版本不支持存储过程,不知道是不是真的。我的mysq的版本是5.1的应该是支持存储过程的。
      

  4.   

    直接这样就行了。
    create procedure prcGetArticleSumScore (v_cteachNo char(6),v_Begin datetime,v_End datetime) 
    select sum(artiScore) as artiSumScore from teacher_article_view
    where cteachNo = v_cteachNo and (dpubtime > v_Begin and dpubtime  < v_End );