> For the complete documentation index, see [llms.txt](https://chankyungpak.gitbook.io/ebis3003-2021/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chankyungpak.gitbook.io/ebis3003-2021/assignments/homework-assignment-1/solutions.md).

# 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;
```
