GoodThought NGO has been a catalyst for positive change, focusing its efforts on education, healthcare, and sustainable development to make a significant difference in communities worldwide. With this mission, GoodThought has orchestrated an array of assignments aimed at uplifting underprivileged populations and fostering long-term growth.
This project offers a hands-on opportunity to explore how data-driven insights can direct and enhance these humanitarian efforts. In this project, you'll engage with the GoodThought PostgreSQL database, which encapsulates detailed records of assignments, funding, impacts, and donor activities from 2010 to 2023. This comprehensive dataset includes:
Assignments: Details about each project, including its name, duration (start and end dates), budget, geographical region, and the impact score.Donations: Records of financial contributions, linked to specific donors and assignments, highlighting how financial support is allocated and utilized.Donors: Information on individuals and organizations that fund GoodThought’s projects, including donor types.
Refer to the below ERD diagram for a visual representation of the relationships between these data tables:
You will execute SQL queries to answer two questions, as listed in the instructions. Good luck!
-- highest_donation_assignments
-- list of total_donation per assignment name and donor type
WITH assignments_ordering AS (
SELECT a.assignment_id, a.assignment_name, d2.donor_type,
ROUND(SUM(d1.amount), 2) AS rounded_total_donation_amount,
RANK() OVER(ORDER BY SUM(d1.amount) DESC) AS rank_assignment
FROM assignments a
INNER JOIN donations d1 ON a.assignment_id = d1.assignment_id
INNER JOIN donors d2 ON d1.donor_id = d2.donor_id
GROUP BY a.assignment_name, d2.donor_type, a.assignment_id
)
SELECT ao.assignment_name, a.region, ao.rounded_total_donation_amount, ao.donor_type
FROM assignments_ordering ao
INNER JOIN assignments a ON ao.assignment_id = a.assignment_id
WHERE ao.rank_assignment < 6
ORDER BY ao.rounded_total_donation_amount DESC-- top_regional_impact_assignments
-- assignment with the highest impact score in each region
WITH regional_impact_score AS (
SELECT assignment_id, ROW_NUMBER() OVER(PARTITION BY region ORDER BY impact_score DESC) AS rank_impact
FROM assignments
),
num_donations AS (
SELECT assignment_id, COUNT(donation_id) AS num_total_donations
FROM donations
GROUP BY assignment_id
HAVING COUNT(donation_id) >= 1
)
SELECT a.assignment_name, a.region, a.impact_score, nd.num_total_donations
FROM assignments a
JOIN regional_impact_score ris ON a.assignment_id = ris.assignment_id
JOIN num_donations nd ON ris.assignment_id = nd.assignment_id
WHERE ris.rank_impact = 1
ORDER BY a.region ASC;