'Need to update SQL script with new custom fields

Basically I have a SQL script that's meant to insert data into a table in WordPress for reporting. And currently it looks like this:

SELECT
TRIM(Nroute.meta_value) AS 'NRoute',
Schools.post_title AS 'Name',
1 AS 'Count'
FROM wp_posts Schools
LEFT JOIN wp_postmeta SchoolOptIn
ON SchoolOptIn.post_id = Schools.id AND SchoolOptIn.meta_key = 'send_automatic_deliveries'
LEFT JOIN wp_postmeta Nroute
ON Nroute.post_id = Schools.id
AND Nroute.meta_key = 'school_route_no1_route_id'
AND TRIM(Nroute.meta_value) != 'N/A'
WHERE Schools.post_type = 'school'
AND SchoolOptIn.meta_value = 1
GROUP BY NRoute, Name
ORDER BY NRoute, Name

The important thing here is the send_automatic_deliveries key which is a checkbox on the Schools custom post type, essentially a true or false.

We now want to expand this functionality out to include different year groups, so I have started by adding a new checkbox for a different year group, and the new key for this is 'send_automatic_deliveries_ece'. The previous key is unchanged. In the backend on WP it looks like this:

WP Backend

My question is how to update the SQL script to include the new key so it checks both 'send_automatic_deliveries' and 'send_automatic_deliveries_ece'.

Thanks for your help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source