SELECT category,
       lat,
       lon,
       part_of_month,
       start_date,
       area_impacted_in_ha,
       country_name,
       location_name,
       execution_time
FROM `fao-maps.fao_locusts.vw_locusts_master`
WHERE ((@cat = "all" or category = @cat) and 
      (
       (@period = "l1w" and start_date >= date_add(DATE_TRUNC(current_date(), WEEK(SUNDAY)), interval -7 day) and start_date <= DATE_TRUNC(current_date(), WEEK(SUNDAY))) OR
       (@period = "l1m" and start_date >= date_add(DATE_TRUNC(current_date(), month), interval -1 month) and start_date < DATE_TRUNC(current_date(), month)) OR
       (@period = "l3m" and start_date >= date_add(DATE_TRUNC(current_date(), month), interval -3 month) and start_date < DATE_TRUNC(current_date(), month)) OR
       (@period = "l6m" and start_date >= date_add(DATE_TRUNC(current_date(), month), interval -6 month) and start_date < DATE_TRUNC(current_date(), month)) OR
       (@period = "l1y" and start_date >= date_add(DATE_TRUNC(current_date(), year), interval -1 year) and start_date < DATE_TRUNC(current_date(), year)) OR
       (@period = "all")
      ))
group by 1,2,3,4,5,6,7,8,9;