函数一 DROP PROCEDURE IF EXISTS `rep_vol_age_distribution`; CREATE DEFINER = `zysadmin`@`%` PROCEDURE `rep_vol_age_distribution`(IN codeLen int,IN districtId varchar(32),In isNotLevel int) IF isNotLevel <> 1 AND districtId IS NOT NULL AND districtId <> '' THEN SET @yearCol_15=CONCAT(@yearCol_15,'GROUP BY years HAVING years BETWEEN 0 and 100 ORDER BY years '); SET @v_sql=CONCAT('(',@yearCol_15,') UNION ALL (',@yearCol_18,')'); SET @v_sql=CONCAT('SELECT CASE WHEN t.years BETWEEN 1 AND 20 THEN \'20岁及以下\' ', PREPARE stmt from @v_sql; EXECUTE stmt ; DEALLOCATE PREPARE stmt; END; 函数二 DROP PROCEDURE IF EXISTS `rep_vol_serviceTime`; CREATE DEFINER = `zysadmin`@`%` PROCEDURE `rep_vol_serviceTime`(In districtId varchar(32),IN startTime varchar(20) ,IN endTime varchar(20)) COMMENT '按时间按地区按项目类型查询志愿服务时间分布' BEGIN SET @districtId=districtId; SET @startTime=startTime; SET @endTime=endTime; SET @v_sql= concat('SELECT mt.type_name,SUM(res.sum_serhour) AS sum_serhour FROM (', 'SELECT m.mission_type,SUM(msl.service_minute) /60 as sum_serhour ', 'FROM mission_service_log msl ', 'LEFT JOIN mission m ON m.mission_id=msl.mission_id WHERE 1=1 '); IF districtId IS NOT NULL AND districtId <> '' THEN SET @v_sql= concat(@v_sql,'AND m.district_id = @districtId '); END IF; IF startTime IS NOT NULL AND startTime <> '' THEN SET @v_sql= concat(@v_sql,'AND msl.check_on_date >= @startTime '); END IF; IF endTime IS NOT NULL AND endTime <> '' THEN SET @v_sql= concat(@v_sql,'AND msl.check_on_date <= @endTime '); END IF; SET @v_sql= concat(@v_sql,'GROUP BY msl.mission_id) AS res ', 'LEFT JOIN mission_type mt ON mt.mission_type_id=res.mission_type ', 'GROUP BY res.mission_type'); PREPARE stmt from @v_sql; EXECUTE stmt ; DEALLOCATE PREPARE stmt; END; |
|