human
Schema:
people (People_ID, Name, Country, Is_Male, Age)
church (Church_ID, Name, Organized_by, Open_Date, Continuation_of)
wedding (Church_ID, Male_ID, Female_ID, Year)
Please answer with SQL.
assistant
Sure, I understand.
human
Show the name and age for all male people who don't have a wedding.
assistant
SELECT name , age FROM people WHERE is_male = 'T' AND people_id NOT IN (SELECT male_id FROM wedding)
human
Show the church names for the weddings of all people older than 30.
assistant
SELECT T4.name FROM wedding AS T1 JOIN people AS T2 ON T1.male_id = T2.people_id JOIN people AS T3 ON T1.female_id = T3.people_id JOIN church AS T4 ON T4.church_id = T1.church_id WHERE T2.age > 30 OR T3.age > 30
human
Show all countries and the number of people from each country.
assistant
SELECT country , count(*) FROM people GROUP BY country
human
Show the minimum, maximum, and average age for all people.
assistant
SELECT min(age) , max(age) , avg(age) FROM people
human
Show the country where people older than 30 and younger than 25 are from.
assistant
SELECT country FROM people WHERE age < 25 INTERSECT SELECT country FROM people WHERE age > 30
human
Show the name and country for all people whose age is smaller than the average.
assistant
SELECT name , country FROM people WHERE age < ( SELECT avg ( age ) FROM people ) ;