DAY3ASSgn

download DAY3ASSgn

of 3

Transcript of DAY3ASSgn

  • 8/3/2019 DAY3ASSgn

    1/3

    Tables

    Department

    dept_code varchar2 (4)

    dept_name varchar2 (20)

    Employee

    emp_code number (5),

    emp_name varchar2 (25) not null,

    dept_code varchar2 (4),

    grade varchar2 (2),age number (2),

    date_join date,

    sex varchar2 (1),

    salary number (6),

    married varchar2 (1),

    reports_to number (5)

    Product

    prod_code number (4),

    prod_name varchar2 (40),

    prodgr_code number (2),

    sale_price number (6, 2),

    target number (5),

    direct_sales number (5),

    indirect_sales number (5),

    profit_margin number (4, 2)

    Prodgrp

    prodgr_code number (2),prodgr_name varchar2 (20)

    State

    state_code varchar2 (4),

    state_name varchar2 (20)

    City

    city_code varchar2 (4),

    city_name varchar2 (20) not null,state_code varchar2 (4)

    Salesman

    emp_code number (5),

    emp_name varchar2 (25) not null,

    age number (2),

    date_join date,

    sex varchar2 (1),

    salary number (6),

    married varchar2 (1),

    reports_to number (5) ,

    Customer

    cust_code number (5),

    cust_name varchar2 (25) not null,

    city_code varchar2 (4),

    credit_rating varchar2 (1)

    Orders

    order_number number (5),

    order_date date not null,

    cust_code number (5),emp_code number (5)

    Order_detail

    order_number number (5),

    prod_code number (4),

    quantity number (5)

  • 8/3/2019 DAY3ASSgn

    2/3

    Consider the following Relations between the above table :

    Aggregate Functions (use tables orders/order_detail/product/employee)

    1. Get a count of the orders.

    2. Get a count of customers who have placed orders.

    3. Get a count of salesman who have booked orders.

    4. Get a count of departments which have some employees.

    5. Get a count of products which have been ordered.

    6. Get the total salary paid in the organization.7. Get the total salary paid to management grade employees. Management grade code begins with

    the letter M.8. Get total value of all orders.

    9. Get average age of male employees.

    10. Get average age of female employees.

    11. Get all details for the product which has the lowest profit margin.

    12. Get all details for the employee who has the highest salary in the organization.

    13. For each department, list the employee who has worked for the longest duration with the

    company. Show department name, employee name, and the number of days worked.

    GROUP BY and HAVING Clauses (employee, department, prodgrup, product, customer,

    orders, order_detail)

    1. Get department-wise total of salary paid.= select sum(sal),dno from emp

    group by dno

    2. 2. Sort the above list by descending order of salary paid.= selectsum(sal),dno from emp group by dno order by sal desc

    3. 3. Sort the above list by department code.= select sum(sal),dno from empgroup by dno order by dno

    4. 4. Sort the above list by department name. select sum(sal),dno from emp

    group by dno order by dname

    5. Get product-group-wise total of targets. Sort the list by product group name.

    6. Get product-group-wise total of sales. Sort the list in descending order of

    total sales.7. Get the staff strength for all departments. Sort by department name.

    8. Get the total number for each product group. Sort in descending order of

    product count for a group.

    9. Get a list of those departments where the average age of employees is more

    than 35 years.

    Sort by descending order of average age. Display department name, average

    age.

  • 8/3/2019 DAY3ASSgn

    3/3

    10. Get a list of those customers who have placed at least two orders. Show

    customer name, number of orders. Sort by customer name.

    11. Get total product-wise quantity ordered.

    Joining Tables (customer, city, state,product,order_detail,orders,employee,salesman)

    1. Get a list of all customers from Rajasthan. Sort the list by customer name.

    2. Get a list of all products for which any orders exist. Sort the list by product name.3. Get a list of all products which have never been ordered. Sort the list by product name.

    4. For each order, list order number, date, customer code and customer name. Sort the list by order

    date.

    5. For each order, list order number, date, customer name, city name. Sort by order date.

    6. For each order, list order number, date, customer name, city name, state name. Sort by order

    number.

    7. Get a list of all orders where the customer is in Gujarat. Sort by order number.

    8. Get a list of all possible female-male pairs in the organization. Sort by female name, male name.9. Get a list of all possible male-female pairs within a department, for the entire organization. Sort by

    male name, female name.

    10. Get a list of all possible pairs of one unmarried male and one unmarried female in the

    organization, where the male is elder than the female. Sort by male name, female name.

    11. Get a list of all employees who report to a person younger than them.

    12. Get a list of all employees who joined the organization earlier than the person they report to.

    13. Get a list of all customers who have ordered any product with prodgr_code = 1. Sort the list by

    customer name.14. Get a list of salesmen who have not booked any orders. Sort the list by salesman name.