SQL Assignment 2
SQL Assignment 2
Q1) Write a SQL query to create table salesman which has the following columns salesman_id |
name | city where id starts from 5001 till 5007.
SYNTAX:
CREATE TABLE salesman(
salesman_id int,
name varchar(20),
city varchar(20));
Q2) Write a SQL statement that displays all the information about all salespeople.
SYNTAX:
SELECT * FROM salesman;
OUTPUT:
Q3) CREATE an order table with columns ord_no purch_amt ord_date customer_id
salesman_id where sales id is 5001 till 5007
SYNTAX:
CREATE TABLE orders(
ord_no int,
purch_amt number(10,2),
ord_date date,
customer_id varchar(10),
salesman_id int, FOREIGN KEY (salesman_id) REFERENCES salesman(salesman_id));
OUTPUT:
Q4) From the order table, write a SQL query to calculate total purchase amount of all orders.
Return total purchase amount.
SYNTAX:
SELECT SUM(purch_amt) AS total_purchase_amount FROM orders;
OUTPUT:
Q5) From the following table, write a SQL query to calculate the average purchase amount of all
orders.
SYNTAX:
SELECT AVG(purch_amt) AS average_purchase_amount FROM orders;
OUTPUT:
SYNTAX:
SELECT o.salesman_id, o.ord_no,
(SELECT s.city
FROM salesman s
WHERE s.salesman_id = o.salesman_id) AS city
FROM orders o;
OUTPUT:
Answer: