# Solutions

## 1. Donations

* What is the average total amount (in $) of donations made to **each project**? If two donations that amount to $10 and $20 respectively were made to project A, the total donation to project A is $30.

```
SELECT AVG(sums)
FROM (SELECT SUM(total_amount) as sums
	FROM donations
    GROUP BY project_id) x ;
```

* How many did **unique** projects receive a donation at least once according to `donations` table?&#x20;

```
SELECT COUNT(DISTINCT project_id)
FROM donations;
```

* Some donations 'complete' projects, meaning that those **last** donations made to projects enabled the projects to achieve the monetary goal they set up front. Whether a donation completes a project is recorded in the column `completion`. Are donations that complete projects substantially larger/smaller than other donations?

```
SELECT AVG(total_amount)
FROM donations
WHERE completion = 1;
```

```
SELECT AVG(total_amount)
FROM donations
WHERE completion = 0
AND funded = 1;
```

## 2. Donors

* Count the numbers of donors from each `state`.

```
SELECT state, COUNT(1) as num
FROM donors
GROUP BY state;
```

* Does average amount of donation (`avg_total`) differ between one-time donor (`num_projeccts=1`) v. more-than-once donor (`num_projects>1`)?&#x20;

```
SELECT avg(avg_total)
FROM donors
WHERE num_projects = 1;
```

```
SELECT avg(avg_total)
FROM donors
WHERE num_projects > 1;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chankyungpak.gitbook.io/ebis3003-2021/assignments/homework-assignment-1/solutions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
