Write following queries given these schemas:
(FK stands for Foreign Key)
Focus should be on using:
3.15 Customer ID, first name and last name of customers who own accounts at a max of four different branches, order by Last Name and first Name.
3.16 Average income of customers older than 60 and average income of customers younger than 20, the result must have two named columns, with one row, in one result set (hint: look up SQLite time and date functions).
3.17 Customer ID, last name, first name, income, and average account balance of customers who have at least three accounts, and whose last names begin with S* and contain an *e (e.g. S**teve) **or whose first names begin with A* and have the letter *n just before the last 2 letters (e.g. Anne), order by customer ID. Note that to appear in the result customers must have at least 2 accounts and satisfy one (or both) of the name conditions.
3.18 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.
3.19 Branch name, account type, and average transaction amount of each account type for each branch for branches that have at least 50 accounts of any type, order by branch name, then account type.
3.20 Branch name, account type, account number, transaction number and amount of transactions of accounts where the average transaction amount is greater than three times the (overall) average transaction amount of accounts of that type. For example, if the average transaction amount of all business accounts is 2,000 then return transactions from business accounts where the average transaction amount for that account is greater than 6,000. Order by branch name, then account type, account number and finally transaction number. Note that all transactions of qualifying accounts should be returned even if they are less than the average amount of the account type.
(FK stands for Foreign Key)
Focus should be on using:
3.15 Customer ID, first name and last name of customers who own accounts at a max of four different branches, order by Last Name and first Name.
3.16 Average income of customers older than 60 and average income of customers younger than 20, the result must have two named columns, with one row, in one result set (hint: look up SQLite time and date functions).
3.17 Customer ID, last name, first name, income, and average account balanceof customers who have at least three accounts, and whose last names begin with S* and contain an *e (e.g. S**teve) **or whose first names begin with A* and have the letter *n just before the last 2 letters (e.g. Anne), order by customer ID. Note that to appear in the result customers must have at least 2 accounts and satisfy one (or both) of the name conditions.
3.18 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.
3.19 Branch name, account type, and average transaction amount of each account type for each branch for branches that have at least 50 accounts of any type, order by branch name, then account type.
Answer:
Query-1
select a.branchName as Branch,b.FirstName as
Manager_FirstName,b.lastName as Manager_LastName
from branch as a innerjoin employee as b
ON a.managerSIN = b.sin;
Query-2
select a.sin as Employee_SIN,CONCAT(a.FIRSTNAME, '
', a.LASTNAME) as EMPLOYEE_NAME
from employee as a innerjoin customer as b
ON a.firstname = b.firstname AND a.lastname =
b.lastname;
Query-3
select a.accNumber as AccountNumber,a.type as
AccountType,a.balance as AccountBalance,b.b.amount as
TransactionAmount
from account as a innerjoin transaction as b
on a.accNumber = b.accNumber
where a.balance>100000 AND b.amounnt>15000
order by b.amount DESC,a.balance DESC;
Query-4
select a.customerID as CustomerID,a.firstname as
Customer_FirstName,a.lastname as Customer_LastName
from customer as a innerjoin owns as b ON a.customerID =
b.customerID
innerjoin Account as c ON b.accNumber = c.accNumber
innerjoin Branch as d ON c.branchNumber = d.branchNumber
where d.branchName = 'london' OR d.branchName = 'Berlin'
order by a.lastname,a.firstname;
Write following queries given these schemas: (FK stands for Foreign Key) Customer = {customerID, firstName, lastName,...
Write following queries given these schemas: (FK stands for Foreign Key) Customer = {customerID, firstName, lastName, income, birthDate} Account = {accNumber, type, balance, branchNumberFK-Branch} Owns = {customerIDFK-Customer, accNumberFK-Account} Transactions = {transNumber, accNumberFK-Account, amount} Employee = {sin, firstName, lastName, salary, branchNumberFK-Branch} Branch = {branchNumber, branchName, managerSINFK-Employee, budget} Focus should be on using: Order By to sort data Set Operators to union/intersect multiple tables Join Operator to join multiple tables Aggregations and Group By to aggregate data Subqueries 3.8 SIN, first name,...
EXERCISE Provide working SQL DML statements for the following database schema and queries CUSTOMER (ID, Type, Firstname, Lastname, Address, City) INVENTORY(ID, ItemName, Type, MadeInStore, SupplierName, DailyAverageSold, Price) ORDERS(ID, Customer_FK, Item_FK, Quantity, DeliveryDate) 16. Find the total amount due for each order, where the total is at least $70 . Show: order id, lastname, and total-amount . Hint: variation of previous query 17. Find the total amount due for each order placed by a customer that is a restaurant owner, total...
Using the database: Write SQL queries for each of the questions
below.
1. Find the media type which
has 100 or more tracks. Print the name of such media type. Number
of rows returned in the result = 3
A) Find the playlists which have one or more tracks that have
never been purchased in California (CA). Print the Id, and the name
of such playlists. Number of rows returned in the result = 18
B) Find the customers who...
Consider the following relational database schema- Doctor(SSN,FirstName,LastName,Speciality,YearsOfExperience,PhoneNum) Patient(SSN,FirstName,LastName,Address,DOB,PrimaryDoctor_SSN) Medicine(TradeName,UnitPrice,GenericFlag) Prescription(Id,Date,Doctor_SSN,Patient_SSN) Prescription_Medicine(Prescription_Id,Trade_Name,NumOfUnits) Write Relational Algebra expression for the following: List the first and last name of patients whose primary doctor named “Rahul kumar” List the first and last name of doctors who are not primary doctors of any patient List the first and last name of patients who have no prescription written by doctors other than the primary doctors List the trade name of generic medicine with unit price greater than...
2. Design an ER-diagram for a bank that implements the following requirements. The database you design should store information about customers, accounts, branches and employees • Customer: Customers are identified by their SSN. For each customer we store a name, multiple phone numbers (one or more), and an occupation. • Account: Accounts are identified by an account number and the branch they belong to. For each account we store a balance and the type of account (e.g., savings). – An...
-----------------------------------
public class Customer
{
String firstName,lastName;
//constructor
public Customer(String firstName,String lastName)
{
this.firstName=firstName;
this.lastName=lastName;
}
//override toString() method
public String toString()
{
return this.lastName+", "+this.firstName;
}
boolean equals(Customer obj)
{
if(this.firstName.equals(obj.firstName) &&
this.lastName.equals(obj.lastName))
return true;
else
return false;
}
}
-----------------------------------
public class Ingredient
{
String ingredientName;
int amount;
double price;
public Ingredient(String ingredientName,int amount,double
price)
{
this.ingredientName=ingredientName;
this.amount=amount;
this.price=price;
}
double getCost()
{
return amount/1000.0*price;
}
public String toString()
{
return this.ingredientName+", "+this.amount+" mls,
$"+this.price+"/L";
}
}
-----------------------------------...
(TCO 7) Write a query to display the orderid, order date, customer last name and firstname for all orders that have shipped. SalesRep Customer ReplD int PK CustomerID int LastName FirstName Commission Rate varchar(20) varchar(20) decimal(10,2) LastName FirstName Street City State Zipcode Balance ReplD varchar(20) varchar(20) varchar(20) varchar(20) char(2) char(5) HO----O decimal(10,2) Order OrderID PK int FK1 int FK1 CustomerID OrderDate ShipDate date date Part PK PartID int Orderline varchar(20) int Description UnitsOnHand Item Class Retail Cost PK,FK1 OrderID PartID...
1. Given the following BANKING database, formulate a Relational Algebra expression for each of the following questions. SELECT should be performed before any JOIN operation. Notation: use the symbol S for SELECT, P for PROJECT, J for INNER JOIN, * for NATURAL JOIN, LJ for LEFT JOIN, RJ for RIGHT JOIN, R for RENAME, and F for FUNCTION. Please type your answer; hand-writing is not accepted. branch(branch_name, branch_city, assets) customer (customer_name, customer_street, customer_city) loan (loan_number, branch_name, amount) borrower (customer_name, loan_number)...
In using a database created from this model, which of the
following SQL queries would give us a list of customers who have
daily deposit transactions (deposit is a
transaction type) totaling $10,000 or more across all of
their accounts (i.e., this is a total across all accounts of a
customer, not per account). Include in this list the Customer ID
and name, and the dates and their respective daily total.
SELECT c.cust_id, c.cust_name, DATE(t.tran_date), SUM(t.tran_amount) AS daily_total
FROM Customers...
Write SQL statements to answer the following questions using Assignment 3’s schema (tables from part 1). 1- Find how many branches had have loans over $2000.00. 2- For each branch, find the most expensive loan. Your output should include Branch Id, loan amount for the highest loan for that Branch. 3- Find how many accounts there are for each customer. The output should include customer id and number of accounts for that customer. 4- Find the total balance amount of...