Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help answer 16 and 17 or 18 and 20 if you can. This is all the information I was given below. As per the

Please help answer 16 and 17 or 18 and 20 if you can. This is all the information I was given below. As per the instructions you cannot use JOIN statements or subqueries.

image text in transcribedimage text in transcribed

Here are the other questions for reference to 19 and 20

image text in transcribedimage text in transcribed

Background Suppose you work at a bank as a data analyst. Your main job is to analyze the data stored in their database. The database has five tables, whose schema is shown as below. Primary keys attributes are underlined and foreign keys are noted in the superscript. Customer = {customerID, firstName, lastName, income, birthDate} Account = {accNumber, type, balance, branchNumber*K-Brunch} Owns = {customerIDFK-Customer, accNumberlK-Account} Transaction = {transNumber, accNumber"K-Account, amount} Employee = {ssn, firstName, lastName, salary, branchNumberK-Branch} Branch = {branchNumber, branchName, managerSSNFK-Employee, budget} Notes. The customerID attribute (Customer) is a unique number that represents a customer, it is not a cus- tomer's SSN The accNumber attribute (Account) represents the account number The balance (Account) attribute represents the total amount in an account The type (Account) attribute represents the type an account: checking, saving, or business The transNumber attribute (Transactions) represents a transaction number, combined with account number it uniquely identify a transaction The branchNumber attribute (Branch) uniquely identifies a branch The manager SSN attribute (Branch) represents the SSN of the branch manager Questions Write SQL queries to return data specified in questions 1 to 20 (each is worth 5pts), which has to satisfy the following requirements: The answer to each question should be a single SQL query. You must order each query as described in the question, order is always ascending unless specified otherwise Every column in the result should be named. So if the query ask you to return something like income times 10, make sure you include an AS statement to name the column. While your question will not be assessed on their efficiency, marks may be deducted if unnecessary tables are included in the query (e.g., including both Owns and Customer when you only require the customerID of customers who own accounts). You may use some date functions in the following questions. In this homework, you should refer to the date and time functions of MySQL (which is also compatible with MariaDB). For more details, please refer to this page. In this homework, you are NOT allow to use JOIN keyword or subqueries. 1. Return rows in the Customers table representing customers who were born after January 1, 1995 and has an income less then $25,000. 2. Return first name, last name, and income of customers who earns the 20 highest income among all customers who own an account in New York branch, order by income (descending). 3. Return first name, last name, and income of customers whose income is within (60000, 70000) ordered by income (descending), lastName, firstName. 4. Return SSN, branch name, salary, and (manager's salary - salary) (that is, the salary of a employee's manager minus salary of that employee) of all employees in New York, London or Berlin, order by ascending (manager's salary - salary). 5. Count the number of joint accounts (i.e., accounts owned by at least two different customers) in New York branch. 6. Return customerID, first name, last name, and income of customers who owns an account with balance greater than $5,000 in either Philadelphia branch or New York branch (not in both branches). 7. Return the customer IDs of customers whose accounts have no transactions with amounts of which the absolute value is less than $3,000 (i.e. all their transactions are either greater than or equal to $3,000 or less than or equal to $3,000). 8. Return branch name of branches whose budget is less than the sum of salaries for all its employees. 9. Return first name, last name, and income of customers whose income are at least twice the that of any customer whose lastName is Smith, order by last name then first name. Note that no duplicate customer information should be provided in the final results. 10. Return customer ID, income, account numbers and branch numbers of customers with income greater than $90,000 who own an account at both London and New York branches, order by customer ID then account number. The result should contain ALL the account numbers of customers who meet the criteria, even if the account itself is not held at London or New York. 11. Return customer ID, types, account numbers, and balances of all business and savings accounts owned by customers who own at least one business account or at least one savings account, order by customer ID, then type, then account number. 12. Return branch name, account number and balance of accounts with balances greater than $110,000 held at the branch managed by Phillip Edwards, order by account number. 13. Return SSN, first name, last name and salary of the lowest paid employee (or employees) of the London branch. 14. Return branch name, and the difference between maximum and minimum salary (salary gap) and average salary of the employees at each branch, order by branch name. 15. Count of the number of different last names of employees working at the New York branch. 16. List 10 different last names of employees such that the average salary of employees in London branch sharing one of them is above $10,000. 17. Return the average income of customers from different age group (where age group is formed in a unit of 10 years, i.e., [0,10), [10,20), .--). Note that you can calculate a customer's age by subtracting his/her birth year from the current year. 18. Return customer ID, first name, last name, income and the average account balance of customers who have at least three accounts, and whose last names begin with 's' and contain an 'e' (e.g. Steve) OR whose first names begin with 'a' and have the letter 'n' just before the last 2 letters (e.g. Anne). Note that to appear in the result customers must have at least 3 accounts and satisfy one (or both) of the name conditions. 19. Return account number, balance, sum of transaction amounts, and (balance - transaction sum) for accounts in the London branch that have at least 15 transactions, order by transaction sum. 20. Return customer ID, first name, last name of the customers who have a total account balance in all branches greater than $300,000 but has less than $100,000 in the total balance of their accounts at the New

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions