joeyd
11/14/2016 - 6:49 PM

sql-query.sql

SELECT
  temp_vacations.RequestID,
  temp_vacations.date_created,
  temp_vacations.`Name`,
  temp_vacations.Email,
  temp_vacations.LeaveType,
  temp_vacations.Details,
  temp_vacations.StartDate,
  temp_vacations.MultipleDates,
  temp_vacations.EndDate,
  temp_vacations.Notes,
 
  GROUP_CONCAT(DISTINCT 
    case when tzo_rg_lead_meta.meta_key = 'approval_status' 
      then tzo_rg_lead_meta.meta_value
          else null 
      end 
    ORDER BY tzo_rg_lead_meta.meta_key ASC 
  ) AS ApprovalStatus

FROM
  temp_vacations
LEFT JOIN 
  tzo_rg_lead_meta ON tzo_rg_lead_meta.lead_id = temp_vacations.RequestID

WHERE 
  ( temp_vacations.StartDate BETWEEN DATE_SUB(NOW(), INTERVAL 1 WEEK) AND NOW() 
	OR temp_vacations.EndDate BETWEEN DATE_SUB(NOW(), INTERVAL 1 WEEK) AND NOW() )

GROUP BY temp_vacations.RequestID
ORDER BY temp_vacations.RequestID