Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE
- ALGORITHM = UNDEFINED
- DEFINER = `root`@`localhost`
- SQL SECURITY DEFINER
- VIEW `rpt_money_collected` AS
- SELECT
- `c`.`id` AS `cemetery_id`,
- SUM((CASE
- WHEN
- ((`ia`.`psvc_fees` = 'pre')
- AND (`ia`.`service_datetime` > ((curdate() - INTERVAL 1 YEAR) - INTERVAL dayofmonth(curdate()) DAY))
- AND (`ia`.`service_datetime` <= (curdate() - INTERVAL dayofmonth(curdate()) DAY)))
- THEN
- ifnull(`ia`.`psvc_pre_charges`, 0)
- ELSE 0
- END)) AS `pre_need_year`,
- SUM((CASE
- WHEN
- ((`ia`.`psvc_fees` = 'at')
- AND (`ia`.`service_datetime` > ((curdate() - INTERVAL 1 YEAR) - INTERVAL dayofmonth(curdate()) DAY))
- AND (`ia`.`service_datetime` <= (curdate() - INTERVAL dayofmonth(curdate()) DAY)))
- THEN
- (ifnull(`ia`.`psvc_fee_amount`, 0) + ifnull(`ia`.`psvc_atneed_charges`, 0))
- ELSE 0
- END)) AS `at_need_year`,
- SUM((CASE
- WHEN
- ((`ia`.`psvc_fees` = 'pre')
- AND (`ia`.`service_datetime` > ((curdate() - INTERVAL 1 MONTH) - INTERVAL dayofmonth(curdate()) DAY))
- AND (`ia`.`service_datetime` <= (curdate() - INTERVAL dayofmonth(curdate()) DAY)))
- THEN
- ifnull(`ia`.`psvc_pre_charges`, 0)
- ELSE 0
- END)) AS `pre_need_month`,
- SUM((CASE
- WHEN
- ((`ia`.`psvc_fees` = 'at')
- AND (`ia`.`service_datetime` > ((curdate() - INTERVAL 1 MONTH) - INTERVAL dayofmonth(curdate()) DAY))
- AND (`ia`.`service_datetime` <= (curdate() - INTERVAL dayofmonth(curdate()) DAY)))
- THEN
- (ifnull(`ia`.`psvc_fee_amount`, 0) + ifnull(`ia`.`psvc_atneed_charges`, 0))
- ELSE 0
- END)) AS `at_need_month`
- FROM
- (`ia_fields` `ia`
- JOIN `cemeteries` `c` ON ((`c`.`id` = `ia`.`cid`)))
- GROUP BY `c`.`id`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement