特定年份存储过程中的mysql总和计算

标签 mysql stored-procedures

我的表是:tbl_fee_payment_history

pk_int_fph_id   fk_int_student_id   int_fph_amount  dat_fph_date
        1           1                 10000         2013-12-11
        2           2                  5000         2013-11-11
        3           1                  5000         2014-12-16
        4           3                  5000         2013-10-19
        5           4                  5000         2014-01-11

我想创建一个存储过程来返回特定年份的总支付金额。

喜欢;

call csp_fee(2013); return value as 20000.

最佳答案

没有测试,但我希望它能起作用。

 DELIMITER $$ 
 drop procedure if exists csp_fee$$
  CREATE  PROCEDURE `csp_fee`(
     IN in_year DECIMAL(18,2),
     OUT in sum_year DECIMAL(18,2))
     BEGIN
     SELECT round(sum(int_fph_amount),2)
      INTO sum_year
      FROM tbl_fee_payment_history where        
      DATE_FORMAT(dat_fph_date,'%Y') = in_year;
   END;
   $$
   DELIMITER ;

关于特定年份存储过程中的mysql总和计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31650409/

相关文章:

mysql - 使用 2 个表中的数据

sql - 存储过程将不返回任何错误消息或编号

sql-server - "There is insufficient system memory in resource pool ' 执行存储过程时默认' to run this query"

mysql根据同一张表选择查询

php - 使用 while 循环和 if 语句从不同表中获取数据

php - 数据库文本在 PHP while 循环中打印两次

php - 拉拉维尔 : relations are not working in every ways of the request

java - 在 voltdb 的存储过程中运行选择查询后出现错误

oracle - 从 JDBC 调用 Oracle 面向对象的 PL/SQL 成员过程

sql - 如何在选择查询中执行存储过程