Advertisement
onejdc

fixforme

Aug 28th, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.06 KB | None | 0 0
  1. CREATE
  2.     ALGORITHM = UNDEFINED
  3.     DEFINER = `root`@`localhost`
  4.     SQL SECURITY DEFINER
  5. VIEW `rpt_money_collected` AS
  6.     SELECT
  7.         `c`.`id` AS `cemetery_id`,
  8.         SUM((CASE
  9.             WHEN
  10.                 ((`ia`.`psvc_fees` = 'pre')
  11.                     AND (`ia`.`service_datetime` > ((curdate() - INTERVAL 1 YEAR) - INTERVAL dayofmonth(curdate()) DAY))
  12.                     AND (`ia`.`service_datetime` <= (curdate() - INTERVAL dayofmonth(curdate()) DAY)))
  13.             THEN
  14.                 ifnull(`ia`.`psvc_pre_charges`, 0)
  15.             ELSE 0
  16.         END)) AS `pre_need_year`,
  17.         SUM((CASE
  18.             WHEN
  19.                 ((`ia`.`psvc_fees` = 'at')
  20.                     AND (`ia`.`service_datetime` > ((curdate() - INTERVAL 1 YEAR) - INTERVAL dayofmonth(curdate()) DAY))
  21.                     AND (`ia`.`service_datetime` <= (curdate() - INTERVAL dayofmonth(curdate()) DAY)))
  22.             THEN
  23.                 (ifnull(`ia`.`psvc_fee_amount`, 0) + ifnull(`ia`.`psvc_atneed_charges`, 0))
  24.             ELSE 0
  25.         END)) AS `at_need_year`,
  26.         SUM((CASE
  27.             WHEN
  28.                 ((`ia`.`psvc_fees` = 'pre')
  29.                     AND (`ia`.`service_datetime` > ((curdate() - INTERVAL 1 MONTH) - INTERVAL dayofmonth(curdate()) DAY))
  30.                     AND (`ia`.`service_datetime` <= (curdate() - INTERVAL dayofmonth(curdate()) DAY)))
  31.             THEN
  32.                 ifnull(`ia`.`psvc_pre_charges`, 0)
  33.             ELSE 0
  34.         END)) AS `pre_need_month`,
  35.         SUM((CASE
  36.             WHEN
  37.                 ((`ia`.`psvc_fees` = 'at')
  38.                     AND (`ia`.`service_datetime` > ((curdate() - INTERVAL 1 MONTH) - INTERVAL dayofmonth(curdate()) DAY))
  39.                     AND (`ia`.`service_datetime` <= (curdate() - INTERVAL dayofmonth(curdate()) DAY)))
  40.             THEN
  41.                 (ifnull(`ia`.`psvc_fee_amount`, 0) + ifnull(`ia`.`psvc_atneed_charges`, 0))
  42.             ELSE 0
  43.         END)) AS `at_need_month`
  44.     FROM
  45.         (`ia_fields` `ia`
  46.         JOIN `cemeteries` `c` ON ((`c`.`id` = `ia`.`cid`)))
  47.     GROUP BY `c`.`id`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement