sql存储过程,查询累加数据

CREATE DEFINER=`anjiplus`@`%` PROCEDURE `get_v_wms_report_working_hour`(
    in_whse_id VARCHAR(100),
    in_operation_date VARCHAR(100),
    in_type VARCHAR(100)
    )
BEGIN
SET @csum:=0;
SET @tsum:=0;
SELECT 
  a.whse_id,
  a.operation_date,
  CONCAT(hourtime, ':', mintime) AS HOUR,
  ROUND(SUBSTRING_INDEX(unit_vol, '/', 1),2) AS v,
  (@csum:= @csum + ROUND(IFNULL(SUBSTRING_INDEX(unit_vol, '/', 1),0),2)) AS sum_v,
  theory_v,
  (@tsum:= @tsum +ROUND(IFNULL(theory_v,0),2)) AS sum_theory
FROM
  v_wms_report_working_hour a
  LEFT JOIN (
SELECT 
whse_id,
operation_date,
ROUND(total_vol/(total_hour*2),3) AS theory_v 
FROM v_wms_report_working_total 
WHERE TYPE=in_type 
AND  whse_id = in_whse_id 
  AND operation_date = in_operation_date
  ) b ON a.whse_id=b.whse_id AND a.operation_date=b.operation_date
WHERE a.whse_id = in_whse_id 
  AND a.operation_date = in_operation_date
  AND a.TYPE = in_type;
    END

 

你可能感兴趣的:(#,mysql)