spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the branch names of banks in the New York state.
SELECT bname FROM bank WHERE state = 'New York'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of banks in the state of New York?
SELECT bname FROM bank WHERE state = 'New York'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
List the name of all customers sorted by their account balance in ascending order.
SELECT cust_name FROM customer ORDER BY acc_bal
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of all customers, ordered by account balance?
SELECT cust_name FROM customer ORDER BY acc_bal
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
List the name of all different customers who have some loan sorted by their total loan amount.
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name ORDER BY sum(T2.amount)
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of the different customers who have taken out a loan, ordered by the total amount that they have taken?
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name ORDER BY sum(T2.amount)
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the state, account type, and credit score of the customer whose number of loan is 0.
SELECT state , acc_type , credit_score FROM customer WHERE no_of_loans = 0
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the states, account types, and credit scores for customers who have 0 loans?
SELECT state , acc_type , credit_score FROM customer WHERE no_of_loans = 0
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the number of different cities which banks are located at.
SELECT count(DISTINCT city) FROM bank
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
In how many different cities are banks located?
SELECT count(DISTINCT city) FROM bank
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the number of different states which banks are located at.
SELECT count(DISTINCT state) FROM bank
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
In how many different states are banks located?
SELECT count(DISTINCT state) FROM bank
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
How many distinct types of accounts are there?
SELECT count(DISTINCT acc_type) FROM customer
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Count the number of different account types.
SELECT count(DISTINCT acc_type) FROM customer
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name and account balance of the customer whose name includes the letter ‘a’.
SELECT cust_name , acc_bal FROM customer WHERE cust_name LIKE '%a%'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names and account balances of customers with the letter a in their names?
SELECT cust_name , acc_bal FROM customer WHERE cust_name LIKE '%a%'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the total account balance of each customer from Utah or Texas.
SELECT sum(acc_bal) FROM customer WHERE state = 'Utah' OR state = 'Texas'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the total account balances for each customer from Utah or Texas?
SELECT sum(acc_bal) FROM customer WHERE state = 'Utah' OR state = 'Texas'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of customers who have both saving and checking account types.
SELECT cust_name FROM customer WHERE acc_type = 'saving' INTERSECT SELECT cust_name FROM customer WHERE acc_type = 'checking'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of customers who have both savings and checking accounts?
SELECT cust_name FROM customer WHERE acc_type = 'saving' INTERSECT SELECT cust_name FROM customer WHERE acc_type = 'checking'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of customers who do not have an saving account.
SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = 'saving'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of customers who do not have saving accounts?
SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = 'saving'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of customers who do not have a loan with a type of Mortgages.
SELECT cust_name FROM customer EXCEPT SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE T2.loan_type = 'Mortgages'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of customers who have not taken a Mortage loan?
SELECT cust_name FROM customer EXCEPT SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE T2.loan_type = 'Mortgages'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of customers who have loans of both Mortgages and Auto.
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE loan_type = 'Mortgages' INTERSECT SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE loan_type = 'Auto'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of customers who have taken both Mortgage and Auto loans?
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE loan_type = 'Mortgages' INTERSECT SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE loan_type = 'Auto'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of customers whose credit score is below the average credit scores of all customers.
SELECT cust_name FROM customer WHERE credit_score < (SELECT avg(credit_score) FROM customer)
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of customers with credit score less than the average credit score across customers?
SELECT cust_name FROM customer WHERE credit_score < (SELECT avg(credit_score) FROM customer)
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the branch name of the bank that has the most number of customers.
SELECT bname FROM bank ORDER BY no_of_customers DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the name of the bank branch with the greatest number of customers?
SELECT bname FROM bank ORDER BY no_of_customers DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of customer who has the lowest credit score.
SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the name of the customer with the worst credit score?
SELECT cust_name FROM customer ORDER BY credit_score LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name, account type, and account balance of the customer who has the highest credit score.
SELECT cust_name , acc_type , acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the name, account type, and account balance corresponding to the customer with the highest credit score?
SELECT cust_name , acc_type , acc_bal FROM customer ORDER BY credit_score DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of customer who has the highest amount of loans.
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name ORDER BY sum(T2.amount) DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the name of the customer who has greatest total loan amount?
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name ORDER BY sum(T2.amount) DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the state which has the most number of customers.
SELECT state FROM bank GROUP BY state ORDER BY sum(no_of_customers) DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Which state has the greatest total number of bank customers?
SELECT state FROM bank GROUP BY state ORDER BY sum(no_of_customers) DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
For each account type, find the average account balance of customers with credit score lower than 50.
SELECT avg(acc_bal) , acc_type FROM customer WHERE credit_score < 50 GROUP BY acc_type
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the average account balance of customers with credit score below 50 for the different account types?
SELECT avg(acc_bal) , acc_type FROM customer WHERE credit_score < 50 GROUP BY acc_type
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
For each state, find the total account balance of customers whose credit score is above 100.
SELECT sum(acc_bal) , state FROM customer WHERE credit_score > 100 GROUP BY state
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the total account balance for customers with a credit score of above 100 for the different states?
SELECT sum(acc_bal) , state FROM customer WHERE credit_score > 100 GROUP BY state
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the total amount of loans offered by each bank branch.
SELECT sum(amount) , T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of the different bank branches, and what are their total loan amounts?
SELECT sum(amount) , T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of customers who have more than one loan.
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name HAVING count(*) > 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of customers who have taken out more than one loan?
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name HAVING count(*) > 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name and account balance of the customers who have loans with a total amount of more than 5000.
SELECT T1.cust_name , T1.acc_type FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name HAVING sum(T2.amount) > 5000
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names and account balances for customers who have taken a total amount of more than 5000 in loans?
SELECT T1.cust_name , T1.acc_type FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id GROUP BY T1.cust_name HAVING sum(T2.amount) > 5000
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of bank branch that provided the greatest total amount of loans.
SELECT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname ORDER BY sum(T2.amount) DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the name of the bank branch that has lent the greatest amount?
SELECT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname ORDER BY sum(T2.amount) DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of bank branch that provided the greatest total amount of loans to customers with credit score is less than 100.
SELECT T2.bname FROM loan AS T1 JOIN bank AS T2 ON T1.branch_id = T2.branch_id JOIN customer AS T3 ON T1.cust_id = T3.cust_id WHERE T3.credit_score < 100 GROUP BY T2.bname ORDER BY sum(T1.amount) DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the name of the bank branch that has lended the largest total amount in loans, specifically to customers with credit scores below 100?
SELECT T2.bname FROM loan AS T1 JOIN bank AS T2 ON T1.branch_id = T2.branch_id JOIN customer AS T3 ON T1.cust_id = T3.cust_id WHERE T3.credit_score < 100 GROUP BY T2.bname ORDER BY sum(T1.amount) DESC LIMIT 1
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name of bank branches that provided some loans.
SELECT DISTINCT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of the different banks that have provided loans?
SELECT DISTINCT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the name and credit score of the customers who have some loans.
SELECT DISTINCT T1.cust_name , T1.credit_score FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the different names and credit scores of customers who have taken a loan?
SELECT DISTINCT T1.cust_name , T1.credit_score FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the the name of the customers who have a loan with amount more than 3000.
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE amount > 3000
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of customers who have a loan of more than 3000 in amount?
SELECT T1.cust_name FROM customer AS T1 JOIN loan AS T2 ON T1.cust_id = T2.cust_id WHERE amount > 3000
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the city and name of bank branches that provide business loans.
SELECT T1.bname , T1.city FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T2.loan_type = 'Business'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names and cities of bank branches that offer loans for business?
SELECT T1.bname , T1.city FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T2.loan_type = 'Business'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the names of bank branches that have provided a loan to any customer whose credit score is below 100.
SELECT T2.bname FROM loan AS T1 JOIN bank AS T2 ON T1.branch_id = T2.branch_id JOIN customer AS T3 ON T1.cust_id = T3.cust_id WHERE T3.credit_score < 100
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What are the names of banks that have loaned money to customers with credit scores below 100?
SELECT T2.bname FROM loan AS T1 JOIN bank AS T2 ON T1.branch_id = T2.branch_id JOIN customer AS T3 ON T1.cust_id = T3.cust_id WHERE T3.credit_score < 100
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the total amount of loans provided by bank branches in the state of New York.
SELECT sum(T2.amount) FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T1.state = 'New York'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the total amount of money loaned by banks in New York state?
SELECT sum(T2.amount) FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id WHERE T1.state = 'New York'
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the average credit score of the customers who have some loan.
SELECT avg(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan)
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the average credit score for customers who have taken a loan?
SELECT avg(credit_score) FROM customer WHERE cust_id IN (SELECT cust_id FROM loan)
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
Find the average credit score of the customers who do not have any loan.
SELECT avg(credit_score) FROM customer WHERE cust_id NOT IN (SELECT cust_id FROM loan)
1
loan_1
CREATE TABLE bank ( branch_ID int PRIMARY KEY, bname varchar(20), no_of_customers int, city varchar(10), state varchar(20)); CREATE TABLE customer ( cust_ID varchar(3) PRIMARY KEY, cust_name varchar(20), acc_type char(1), acc_bal int, no_of_loans int, credit_score int, branch_ID int, state varchar(20), FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID)); CREATE TABLE loan ( loan_ID varchar(3) PRIMARY KEY, loan_type varchar(15), cust_ID varchar(3), branch_ID varchar(3), amount int, FOREIGN KEY(branch_ID) REFERENCES bank(branch_ID), FOREIGN KEY(Cust_ID) REFERENCES customer(Cust_ID))
What is the average credit score for customers who have never taken a loan?
SELECT avg(credit_score) FROM customer WHERE cust_id NOT IN (SELECT cust_id FROM loan)
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
How many assessment notes are there in total?
SELECT count(*) FROM ASSESSMENT_NOTES
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What are the dates of the assessment notes?
SELECT date_of_notes FROM Assessment_Notes
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
How many addresses have zip code 197?
SELECT count(*) FROM ADDRESSES WHERE zip_postcode = "197"
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
How many distinct incident type codes are there?
SELECT count(DISTINCT incident_type_code) FROM Behavior_Incident
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Return all distinct detention type codes.
SELECT DISTINCT detention_type_code FROM Detention
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What are the start and end dates for incidents with incident type code "NOISE"?
SELECT date_incident_start , date_incident_end FROM Behavior_Incident WHERE incident_type_code = "NOISE"
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Return all detention summaries.
SELECT detention_summary FROM Detention
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Return the cell phone number and email address for all students.
SELECT cell_mobile_number , email_address FROM STUDENTS
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What is the email of the student with first name "Emma" and last name "Rohan"?
SELECT email_address FROM Students WHERE first_name = "Emma" AND last_name = "Rohan"
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
How many distinct students have been in detention?
SELECT count(DISTINCT student_id) FROM Students_in_Detention
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What is the gender of the teacher with last name "Medhurst"?
SELECT gender FROM TEACHERS WHERE last_name = "Medhurst"
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What is the incident type description for the incident type with code "VIOLENCE"?
SELECT incident_type_description FROM Ref_Incident_Type WHERE incident_type_code = "VIOLENCE"
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the maximum and minimum monthly rental for all student addresses.
SELECT max(monthly_rental) , min(monthly_rental) FROM Student_Addresses
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the first names of teachers whose email address contains the word "man".
SELECT first_name FROM Teachers WHERE email_address LIKE '%man%'
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
List all information about the assessment notes sorted by date in ascending order.
SELECT * FROM Assessment_Notes ORDER BY date_of_notes ASC
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
List all cities of addresses in alphabetical order.
SELECT city FROM Addresses ORDER BY city
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the first names and last names of teachers in alphabetical order of last name.
SELECT first_name , last_name FROM Teachers ORDER BY last_name
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find all information about student addresses, and sort by monthly rental in descending order.
SELECT * FROM Student_Addresses ORDER BY monthly_rental DESC
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the id and first name of the student that has the most number of assessment notes?
SELECT T1.student_id , T2.first_name FROM Assessment_Notes AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY count(*) DESC LIMIT 1
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the ids and first names of the 3 teachers that have the most number of assessment notes?
SELECT T1.teacher_id , T2.first_name FROM Assessment_Notes AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id GROUP BY T1.teacher_id ORDER BY count(*) DESC LIMIT 3
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the id and last name of the student that has the most behavior incidents?
SELECT T1.student_id , T2.last_name FROM Behavior_Incident AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY count(*) DESC LIMIT 1
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the id and last name of the teacher that has the most detentions with detention type code "AFTER"?
SELECT T1.teacher_id , T2.last_name FROM Detention AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id WHERE T1.detention_type_code = "AFTER" GROUP BY T1.teacher_id ORDER BY count(*) DESC LIMIT 1
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What are the id and first name of the student whose addresses have the highest average monthly rental?
SELECT T1.student_id , T2.first_name FROM Student_Addresses AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY AVG(monthly_rental) DESC LIMIT 1
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the id and city of the student address with the highest average monthly rental.
SELECT T2.address_id , T1.city FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id GROUP BY T2.address_id ORDER BY AVG(monthly_rental) DESC LIMIT 1
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What are the code and description of the most frequent behavior incident type?
SELECT T1.incident_type_code , T2.incident_type_description FROM Behavior_Incident AS T1 JOIN Ref_Incident_Type AS T2 ON T1.incident_type_code = T2.incident_type_code GROUP BY T1.incident_type_code ORDER BY count(*) DESC LIMIT 1
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What are the code and description of the least frequent detention type ?
SELECT T1.detention_type_code , T2.detention_type_description FROM Detention AS T1 JOIN Ref_Detention_Type AS T2 ON T1.detention_type_code = T2.detention_type_code GROUP BY T1.detention_type_code ORDER BY count(*) ASC LIMIT 1
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the dates of assessment notes for students with first name "Fanny".
SELECT T1.date_of_notes FROM Assessment_Notes AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.first_name = "Fanny"
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the texts of assessment notes for teachers with last name "Schuster".
SELECT T1.text_of_notes FROM Assessment_Notes AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id WHERE T2.last_name = "Schuster"
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the start and end dates of behavior incidents of students with last name "Fahey".
SELECT T1.date_incident_start , date_incident_end FROM Behavior_Incident AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id WHERE T2.last_name = "Fahey"
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
Find the start and end dates of detentions of teachers with last name "Schultz".
SELECT T1.datetime_detention_start , datetime_detention_end FROM Detention AS T1 JOIN Teachers AS T2 ON T1.teacher_id = T2.teacher_id WHERE T2.last_name = "Schultz"
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What are the id and zip code of the address with the highest monthly rental?
SELECT T2.address_id , T1.zip_postcode FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id ORDER BY monthly_rental DESC LIMIT 1
1
behavior_monitoring
CREATE TABLE `Ref_Address_Types` ( `address_type_code` VARCHAR(15) PRIMARY KEY, `address_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Detention_Type` ( `detention_type_code` VARCHAR(10) PRIMARY KEY, `detention_type_description` VARCHAR(80) ); CREATE TABLE `Ref_Incident_Type` ( `incident_type_code` VARCHAR(10) PRIMARY KEY, `incident_type_description` VARCHAR(80) ); CREATE TABLE `Addresses` ( `address_id` INTEGER PRIMARY KEY, `line_1` VARCHAR(120), `line_2` VARCHAR(120), `line_3` VARCHAR(120), `city` VARCHAR(80), `zip_postcode` VARCHAR(20), `state_province_county` VARCHAR(50), `country` VARCHAR(50), `other_address_details` VARCHAR(255) ); CREATE TABLE `Students` ( `student_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(40), `last_name` VARCHAR(40), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `date_first_rental` DATETIME, `date_left_university` DATETIME, `other_student_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Teachers` ( `teacher_id` INTEGER PRIMARY KEY, `address_id` INTEGER NOT NULL, `first_name` VARCHAR(80), `middle_name` VARCHAR(80), `last_name` VARCHAR(80), `gender` VARCHAR(1), `cell_mobile_number` VARCHAR(40), `email_address` VARCHAR(40), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ) ); CREATE TABLE `Assessment_Notes` ( `notes_id` INTEGER NOT NULL , `student_id` INTEGER, `teacher_id` INTEGER NOT NULL, `date_of_notes` DATETIME, `text_of_notes` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Behavior_Incident` ( `incident_id` INTEGER PRIMARY KEY, `incident_type_code` VARCHAR(10) NOT NULL, `student_id` INTEGER NOT NULL, `date_incident_start` DATETIME, `date_incident_end` DATETIME, `incident_summary` VARCHAR(255), `recommendations` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`incident_type_code` ) REFERENCES `Ref_Incident_Type`(`incident_type_code` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Detention` ( `detention_id` INTEGER PRIMARY KEY, `detention_type_code` VARCHAR(10) NOT NULL, `teacher_id` INTEGER, `datetime_detention_start` DATETIME, `datetime_detention_end` DATETIME, `detention_summary` VARCHAR(255), `other_details` VARCHAR(255), FOREIGN KEY (`detention_type_code` ) REFERENCES `Ref_Detention_Type`(`detention_type_code` ), FOREIGN KEY (`teacher_id` ) REFERENCES `Teachers`(`teacher_id` ) ); CREATE TABLE `Student_Addresses` ( `student_id` INTEGER NOT NULL, `address_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `date_address_to` DATETIME, `monthly_rental` DECIMAL(19,4), `other_details` VARCHAR(255), FOREIGN KEY (`address_id` ) REFERENCES `Addresses`(`address_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) ); CREATE TABLE `Students_in_Detention` ( `student_id` INTEGER NOT NULL, `detention_id` INTEGER NOT NULL, `incident_id` INTEGER NOT NULL, FOREIGN KEY (`incident_id` ) REFERENCES `Behavior_Incident`(`incident_id` ), FOREIGN KEY (`detention_id` ) REFERENCES `Detention`(`detention_id` ), FOREIGN KEY (`student_id` ) REFERENCES `Students`(`student_id` ) )
What is the cell phone number of the student whose address has the lowest monthly rental?
SELECT T2.cell_mobile_number FROM Student_Addresses AS T1 JOIN Students AS T2 ON T1.student_id = T2.student_id ORDER BY T1.monthly_rental ASC LIMIT 1