0% found this document useful (0 votes)
28 views

Filtering Rows+aggregate Functions

The document provides SQL queries to retrieve data from a 'people' table in a PostgreSQL database. The first query selects names from the table where the second letter is 'r'. The second query calculates the percentage of people in the table who have a deathdate recorded, aliases this result as 'percentage_dead', and correctly uses 100.0 instead of 100 in the calculation.

Uploaded by

dieko
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Filtering Rows+aggregate Functions

The document provides SQL queries to retrieve data from a 'people' table in a PostgreSQL database. The first query selects names from the table where the second letter is 'r'. The second query calculates the percentage of people in the table who have a deathdate recorded, aliases this result as 'percentage_dead', and correctly uses 100.0 instead of 100 in the calculation.

Uploaded by

dieko
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Important: in PostgreSQL

(the version of SQL we're


using), you must use sin-
gle quotes with WHERE
Get the names of people
whose names have 'r' as the
second letter.

select name from people


where name like '_r%'
Get the percentage of people who are no longer alive. Alias the result as percentage_dead.
Remember to use 100.0 and not 100!

SELECT COUNT(deathdate) * 100.0 / COUNT(*) AS percentage_dead FROM people

You might also like