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!
SELECT * FROM assignments;SELECT * FROM donations;
-- Note assignments and donations has 1:N relationshipSELECT * FROM donors;List the top five assignments based on total value of donations, categorized by donor type. The output should include four columns:
- assignment_name,
- region,
- rounded_total_donation_amount rounded to two decimal places, and
- donor_type
Sort by rounded_total_donation_amount in descending order. Save the result as highest_donation_assignments.
-- highest_donation_assignments
SELECT assignments.assignment_name,
assignments.region,
ROUND(SUM(donations.amount), 2) AS rounded_total_donation_amount,
donors.donor_type
FROM assignments
INNER JOIN donations
ON assignments.assignment_id = donations.assignment_id
INNER JOIN donors
ON donations.donor_id = donors.donor_id
GROUP BY assignments.assignment_name, assignments.region, donors.donor_type
ORDER BY rounded_total_donation_amount DESC
LIMIT 5;
Identify the assignment with the highest impact score in each region, ensuring that each listed assignment has received at least one donation. The output should include four columns:
- assignment_name,
- region,
- impact_score, and
- num_total_donations
Sorted by region in ascending order. Include only the highest-scoring assignment per region, avoiding duplicates within the same region. Save the result as top_regional_impact_assignments.
-- top_regional_impact_assignments
WITH impact_assignment AS(
SELECT assignment_name,
region,
impact_score,
SUM(donations.amount) AS num_total_donations,
RANK() OVER(PARTITION BY region ORDER BY impact_score DESC, SUM(donations.amount) DESC) AS rank_per_region
FROM assignments
INNER JOIN donations
ON assignments.assignment_id = donations.assignment_id
GROUP BY assignments.assignment_name, assignments.region, impact_score
ORDER BY impact_score DESC)
SELECT assignment_name,
region,
impact_score,
num_total_donations
FROM impact_assignment
WHERE rank_per_region = 1
ORDER BY region;