SQL Assigment2
SQL Assigment2
ddl -- Homework 3
--
--
;
ALTER TABLE s_warehouse ADD CONSTRAINT s_warehouse_id_pk PRIMARY
KEY ( id ) ;
NULL, '6');
NULL, '7');
NULL, '8');
NULL, '9');
--1. Show the structure of the S_DEPT table. Select all information from the
S_DEPT table, S_CUSTOMER table (hint DESCRIBE s_customer,...)
exec sp_help's_dept';
--2. Display the name and phone number for each customer
--3. Display the phone number and name for each customer, with phone
number appearing first.
select userid as 'user name of employee 23' from s_emp where id = 23;
--5. Display the first name, last name, and department number of the
employees in departments 10 and 50 in alphabetical order of last name.
Group
--7. Display the user names and start date of employees hired between May
5, 1990 and May 26, 1991. Order the query results by start date ascending
order.
--8. Write a query to show the last name and salary of all employees who are
not making between 1000 and 2500 per month
select last_name, salary from s_emp where salary not between 1000 and
2500;
--9. List the last name and salary of employees who earn more than 1350
who are in department 31, 42, or 50. Label the last name column Employee
Name, and label the salary column Monthly Salary
select last_name, salary from s_emp where salary > 1350 and dept_id = 31
or dept_id=42 or dept_id = 50;
--10. Display the last name and start date of every employee who was hired
in 1991
--12. Alphabetically display all products having a name beginning with Pro
--13. Display all product names and short descriptions for all descriptions
containing the word bicycle
--14. Display all short descriptions. Compare the results from above question.
--Yes
--15. Display the employee number, last name, and salary increased by 15%
and expressed as a whole number
--16. Display the employee last name and title in parentheses for all
employees.
--The report should look like the output below : Jonh Herry (Director)
--17. Display each employee’s last name, hire date, and salary review date,
which is the first Monday after six months of service.
--Format the dates to appear in the format similar to Eighth of May 1992
/* select s_emp.last_name,
from s_emp;*/
--18. Display the product name for products that have “ski” in the name
--19. For each employee, calculate the number of months between today and
the date the employee was hired.
SELECT s_emp.userid,
FROM s_emp
ORDER BY MonthsEmployed;
--20. Display the last name for all employees and the day of the week they
started
end as WeekDay
from s_emp s;
/*21. Write a query that produces the following for each employee:
<employee name> earns <salary> monthly but wants <3 times salary>.
select concat( first_name,' ', last_name, ' earns $', salary, ' monthly but
wants $', salary*3, '.' ) as
argggggggggggggggggggggggggggggggggggggggggggggggggg from s_emp
;
--23. Write a query to display the last name, department name, and region
name of all employees who earn a commission.
--25. Display the product name, product number, and quantity ordered of all
items in order number 101. Label the quantity column ORDERED.
--26. Display the customer number and the last name of their sales
representative.Order the list by last name.
--27. Display the customer number, customer name, and order number of all
customers and their orders.
--Display the customer number and name, even if they have not placed an
order
--28. Display all employees by last name name and employee number along
with their manager’s last name and manager number
--30. Display all customers and the product number and quantities they
ordered for those customers whose order totaled more than 100,000
--31. Display the highest and lowest order totals in the S_ORD. Label the
columns Highest and Lowest, respectively.
select max(total) as Highest, min(total) as Lowest from s_ord;
--32. Write a query to display the minimum and maximum salary for each job
type ordered alphabetically
--34. Display the number of line items in each order under each order
number, labeled number of Items
--35. Display the manager number and the salary of the lowest paid
employee for that manager.
--Exclude any groups where the minimum salary is less than 1000. Sort the
output by salary
--36. Display the product number and number of times it was ordered,
labeled Times
--Ordered. Only show those products that have been ordered at least three
times. Order the data by the number of products ordered.
--37. Retrieve the region number, region name, and the number of
departments within region.
--38. Display the order number and total item count for each order of 100 or
more items.
--For example, if order number 99 contains quantity 30 of one item, and
quantity 75 of another item, then the total item count for that order is 105.
--39. Display the customer name and the number of orders for each
customer.
--40. Display the first name, last name, and start date for all employees in
the same department as Magee
--41. Display the employee number, first name, last name, and user name for
all employees with salaries above the average salary.
select id , first_name, last_name, userid from s_emp where salary > (select
avg (salary) from s_emp);
--42. Display the name and short description for any product that did not
appear on an order in the month of September, 1992.
--43. Display each sales representative’s last name in region 1 and region 2,
their customers’ names and each customer’s total sales orders.