From 8c9a19ec973ef9202f91fbd4a0e90d57b243f5b4 Mon Sep 17 00:00:00 2001 From: Michael Reber Date: Mon, 18 Nov 2019 14:05:53 +0100 Subject: [PATCH] Adding SQL query language --- ...e the average price of all the products.sql | 3 +++ ...mpany's products, along with their code.sql | 5 +++++ ...th a price more than or equal to Rs.350.sql | 4 ++++ ... a gradation for hisor her performance..sql | 3 +++ ...all orders for a date August 17th, 2012.sql | 4 ++++ ...erent non NULL city values for salesmen.sql | 4 ++++ ...hest purchase amount is more than 1000..sql | 7 +++++++ ...e average purchase amount of all orders.sql | 3 +++ ...-08-17' for each salesman with their ID.sql | 5 +++++ ... order date and highest purchase amount.sql | 5 +++++ ...th their ID and highest purchase amount.sql | 5 +++++ ...hin the list 2000, 3000, 5760 and 6000..sql | 6 ++++++ ...chase amount in a day is more than 2000.sql | 6 ++++++ ...se customers who have a higher purchase.sql | 6 ++++++ ...se ID is within the range 3002 and 3007.sql | 6 ++++++ ...se ID is within the range 5003 and 5008.sql | 6 ++++++ ...ntly listing for all of their customers.sql | 3 +++ ...he total purchase amount for all orders.sql | 3 +++ ... many customers have listed their names.sql | 3 +++ ...ximum purchase amount of all the orders.sql | 3 +++ ...nimum purchase amount of all the orders.sql | 3 +++ ...for each of the cities of the customers.sql | 4 ++++ ...partment along with the department code.sql | 4 ++++ ...the allotment amount of all departments.sql | 3 +++ ... and ID registering orders for each day.sql | 4 ++++ ...se amount less than a specified amount..sql | 0 ...ase amount less than a specified amount.sql | 7 +++++++ ... or order date and customer_id must not.sql | 7 +++++++ ...eds the 50% of the target value of 6000.sql | 7 +++++++ ...w York nor grade value is more than 100.sql | 4 ++++ ... city New York or had a grade above 100.sql | 4 ++++ ...y New York or not had a grade above 100.sql | 5 +++++ ...salesman whose ID is 505 and below or t.sql | 7 +++++++ ...nge more than 0.10% and less than 0.12%.sql | 6 ++++++ ... work in department 47 or department 63.sql | 4 ++++ ...oyees whose last name is Dosni or Mardy.sql | 4 ++++ ...w York who have a grade value above 100.sql | 4 ++++ ...ay all customers with a grade above 100.sql | 4 ++++ ...to the order_date in such a manner that.sql | 5 +++++ ...r holding highest grade will come first.sql | 5 +++++ ...e and city columns for all the salesmen.sql | 4 ++++ ...d according to the smallest customer ID.sql | 5 +++++ ...hase amount of same day will come first.sql | 5 +++++ ...ay and display it in such a format like.sql | 6 ++++++ ... booked by the customer will come first.sql | 7 +++++++ ...rder number arranged by ascending order.sql | 4 ++++ ..., and department name for each employee.sql | 6 ++++++ ...ees who have or have not any department.sql | 6 ++++++ ... who does not working under any manager.sql | 7 +++++++ ...yee, and starting date for all the jobs.sql | 8 ++++++++ ... for the job and salary of the employee.sql | 6 ++++++ ...g in that department who got commission.sql | 6 ++++++ ...the departments which are running there.sql | 5 +++++ ...me (first and last name) of the manager.sql | 5 +++++ ...b title and average salary of employees.sql | 5 +++++ ...y, and state province for each employee.sql | 8 ++++++++ ...tly earning a salary on and above 12000.sql | 7 +++++++ ...where at leaste 2 employees are working.sql | 12 ++++++++++++ ...d last name) of manager, and their city.sql | 6 ++++++ ... in for all those jobs in department 80.sql | 5 +++++ ...ing in any department located in London.sql | 7 +++++++ ... worked without a commission percentage.sql | 9 +++++++++ ... of employees in each of the department.sql | 5 +++++ ...salary, and job grade for all employees.sql | 5 +++++ ... all employees for departments 80 or 40.sql | 9 +++++++++ ...e, department, city, and state province.sql | 10 ++++++++++ ... those where does not have any employee.sql | 5 +++++ ...n the employee earn whose number is 182.sql | 7 +++++++ ...cluding the first name of their manager.sql | 6 ++++++ ... and state province for each department.sql | 5 +++++ ...ompany, showing the name of the company.sql | 6 ++++++ ...ompany, showing the name of the company.sql | 10 ++++++++++ ...e data for each item's producer company.sql | 5 +++++ ...ompany, showing the name of the company.sql | 6 ++++++ ...e, and company name of all the products.sql | 5 +++++ ... which salesman works for that customer.sql | 10 ++++++++++ ...ves, and gets a commission is above 12%.sql | 9 +++++++++ ...ssion from the company is more than 12%.sql | 8 ++++++++ ...salesman are working for which customer.sql | 6 ++++++ ...for that customer who belongs to a city.sql | 6 ++++++ ...ce versa for those salesmen who belongs.sql | 7 +++++++ ...r those salesmen who must belong a city.sql | 9 +++++++++ ...alesman and customer i.e. each salesman.sql | 5 +++++ ... and only the relational rows will come.sql | 6 ++++++ ...mers or yet to join any of the customer.sql | 13 +++++++++++++ ...not yet join under any of the customers.sql | 10 ++++++++++ ...rks either through a salesman or by own.sql | 9 +++++++++ ...rks either through a salesman or by own.sql | 7 +++++++ ...not yet join under any of the customers.sql | 8 ++++++++ ...which order amount between 500 and 2000.sql | 7 +++++++ ...e list who must have a grade and placed.sql | 9 +++++++++ ...ting list who placed one or more orders.sql | 7 +++++++ ...nding order according to the order date.sql | 9 +++++++++ ...at either any of the existing customers.sql | 11 +++++++++++ ...d customer who belongs to the same city.sql | 6 ++++++ ...ame of the customers who made the order.sql | 4 ++++ ...d commission amount for those customers.sql | 8 ++++++++ ... customers must have a grade and served.sql | 9 +++++++++ ...ng with the salesmen who works for them.sql | 4 ++++ ...ame and city who lives in the same city.sql | 6 ++++++ sql/README.md | 3 +++ ...ts of the manufacturer which code is l6.sql | 3 +++ ...ry to display the Nobel prizes for 1970.sql | 4 ++++ ... company, showing only the company code.sql | 4 ++++ ...bject that won 'Dennis Gabor' his prize.sql | 3 +++ ...the prize won by Johannes Georg Bednorz.sql | 4 ++++ ...subject Economics and Chemistry at last.sql | 12 ++++++++++++ ... with a price between Rs.200 and Rs.600.sql | 3 +++ ...y to find the item name and price in Rs.sql | 3 +++ ...the name and price of the cheapest item.sql | 5 +++++ ...e 'Physics' winners since the year 1950.sql | 5 +++++ ...winner of the 1971 prize for Literature.sql | 5 +++++ ...972 of Menachem Begin and Yitzhak Rabin.sql | 5 +++++ ...between the year 1965 to 1975 inclusive.sql | 6 ++++++ ...ls of the winners with first name Louis.sql | 4 ++++ ...r with the winner of Economics for 1971.sql | 8 ++++++++ ...pt the subject Physiology and Economics.sql | 5 +++++ ...e in a later year on and after the 1974.sql | 9 +++++++++ ...for those customers with a grade of 200.sql | 3 +++ ...mployees that work in the department 57.sql | 4 ++++ ...f employees whose last name is 'Snares'.sql | 4 ++++ ...me of all employees, without duplicates.sql | 3 +++ ... is SQL Exercise, Practice and Solution.sql | 2 ++ ...lay all the columns from salesman table.sql | 16 ++++++++++++++++ ...esman, who belongs to the city of Paris.sql | 4 ++++ ...name and commission from table salesman.sql | 2 ++ ..., and purchase amount from orders table.sql | 3 +++ ...to display sum of two numbers 10 and 15.sql | 2 ++ ... result of an arithmetic simplification.sql | 2 ++ ... display three numbers in three columns.sql | 2 ++ ...ers in orders table without any repeats.sql | 2 ++ ...the salesman who is holding the ID 5001.sql | 5 +++++ ...to find the name and year of the movies.sql | 3 +++ ...r which include the words Boogie Nights.sql | 5 +++++ ...is 'Woody' and the last name is 'Allen'.sql | 5 +++++ ...played a role in the movie 'Annie Hall'.sql | 11 +++++++++++ ...he roles they played in that production.sql | 7 +++++++ ...that casted a role for 'Eyes Wide Shut'.sql | 9 +++++++++ ...that casted a role for 'Eyes Wide Shut'.sql | 16 ++++++++++++++++ ...ovie that casted a role as Sean Maguire.sql | 11 +++++++++++ ...ore 1990 and also in a movie after 2000.sql | 8 ++++++++ ...directed with genres name, and arranged.sql | 9 +++++++++ ...ist all the movies with year and genres.sql | 5 +++++ ...when the movie American Beauty released.sql | 4 ++++ ... year, genres, and name of the director.sql | 7 +++++++ ...h released in the country other than UK.sql | 6 ++++++ ... which released before 1st January 1998.sql | 12 ++++++++++++ ...me and number of movies for each genres.sql | 8 ++++++++ ... and his or her role in that production.sql | 10 ++++++++++ ... those movies which reviewer is unknown.sql | 14 ++++++++++++++ ...ose first and last name are Woddy Allen.sql | 11 +++++++++++ ...ose first and last name are Woddy Allen.sql | 8 ++++++++ ...tles of all movies that have no ratings.sql | 8 ++++++++ ...wers who have ratings with a NULL value.sql | 7 +++++++ ...vie which was released in the year 1999.sql | 4 ++++ ...eviewed by a reviewer and must be rated.sql | 9 +++++++++ ...eviewers who rated more than one movies.sql | 8 ++++++++ ...anged the result according to the group.sql | 8 ++++++++ ...ers who rated the movie American Beauty.sql | 6 ++++++ ...eviewed by anybody except by Paul Monks.sql | 10 ++++++++++ ...e movies which rating is the lowest one.sql | 10 ++++++++++ ...of all movies directed by James Cameron.sql | 11 +++++++++++ ...and sort the result in increasing order.sql | 7 +++++++ ...ie title, and lastly by number of stars.sql | 8 ++++++++ ...e movies which was released before 1998.sql | 4 ++++ ...) they directed and received the rating.sql | 8 ++++++++ ...more actors acted in two or more movies.sql | 13 +++++++++++++ ...more actors acted in two or more movies.sql | 12 ++++++++++++ ...ss appeared which first name was Claire.sql | 14 ++++++++++++++ ...ie which was also directed by themselve.sql | 14 ++++++++++++++ ...d the cast list for the movie Chinatown.sql | 10 ++++++++++ ...and last name are 'Harrison' and 'Ford'.sql | 10 ++++++++++ ...le, year, rating, and releasing country.sql | 8 ++++++++ ... and report the title, year, and rating.sql | 12 ++++++++++++ ...mber of movies and their average rating.sql | 9 +++++++++ ...gether in a single list, alphabetically.sql | 6 ++++++ ...e rated 7 or more stars to their rating.sql | 6 ++++++ ...tles of all movies that have no ratings.sql | 7 +++++++ ...e rated their ratings with a NULL value.sql | 5 +++++ ...les of the movies with ID 905, 907, 917.sql | 4 ++++ ...for those employees who earn below 6000.sql | 4 ++++ ... first name is ending with the letter m.sql | 5 +++++ ...lary is out of the range 7000 and 15000.sql | 6 ++++++ ...who works either in department 70 or 90.sql | 6 ++++++ ... and manager number for those employees.sql | 5 +++++ ...es who was hired before June 21st, 1987.sql | 5 +++++ ...anagers are hold the ID 120, 103 or 145.sql | 6 ++++++ ...name), hire date, commission percentage.sql | 9 +++++++++ ... for those employees who holds a letter.sql | 5 +++++ ...those employees who earn more than 8000.sql | 5 +++++ ...ing except the departments 50,30 and 80.sql | 5 +++++ ...e department number equals 30, 40 or 90.sql | 5 +++++ ...es who did two or more jobs in the past.sql | 5 +++++ ...hest salary and lowest salary for a job.sql | 6 ++++++ ...e by two or more for more than 300 days.sql | 6 ++++++ ...umber of cities in that country we have.sql | 4 ++++ ...ber of employees managed by the manager.sql | 4 ++++ ...obs in descending sequence on job title.sql | 4 ++++ ...me and date of joining of the employees.sql | 5 +++++ ...rtment who gets a commission percentage.sql | 5 +++++ ...all employees whose last name is McEwen.sql | 5 +++++ ...manager is managing 4 or more employees.sql | 5 +++++ ...ents where more than ten employees work.sql | 6 ++++++ ...date on which he ended his previous job.sql | 4 ++++ ...jobs which average salary is above 8000.sql | 5 +++++ ... salary within the range 12000 to 18000.sql | 5 +++++ ...e or last name starts with the letter D.sql | 5 +++++ ...ich minimum salary is greater than 9000.sql | 4 ++++ ...es who joined after 7th September, 1987.sql | 4 ++++ ...employees without any department number.sql | 4 ++++ ...ormation about the department Marketing.sql | 3 +++ ...d department number for those employees.sql | 7 +++++++ ...00 and 12000 and commission is not null.sql | 8 ++++++++ ...loyees who does not earn any commission.sql | 5 +++++ ...), the phone number and email separated.sql | 8 ++++++++ ...able issued by the salesman 'Paul Adam'.sql | 7 +++++++ ...orders issued on date 17th August, 2012.sql | 5 +++++ ...salesmen who had more than one customer.sql | 6 ++++++ ...ove-average amounts for their customers.sql | 6 ++++++ ...ove-average amounts for their customers.sql | 6 ++++++ ...he customer table are located in London.sql | 8 ++++++++ ...he salesmen who have multiple customers.sql | 11 +++++++++++ ...lesmen who worked for only one customer.sql | 10 ++++++++++ ...ave customers with more than one orders.sql | 11 +++++++++++ ... with customers located in their cities.sql | 6 ++++++ ...salesman who belongs to the city London.sql | 7 +++++++ ...om there are customers that follow them.sql | 6 ++++++ ...ly lower than the name of the customers.sql | 7 +++++++ ...abetically lower than the city New York.sql | 8 ++++++++ ...one of the orders from October 9th 2012.sql | 8 ++++++++ ...han any amount for a customer in London.sql | 8 ++++++++ ...han any amount for a customer in London.sql | 8 ++++++++ ... higher than every customer in New York.sql | 7 +++++++ ...han every customer to the city New York.sql | 8 ++++++++ ...customer who belongs to the city London.sql | 8 ++++++++ ...as the grade, belongs to the city Paris.sql | 7 +++++++ ...who works for customer whose id is 3007.sql | 7 +++++++ ...de than any customer of the city Dallas.sql | 7 +++++++ ...erage order value for 10th October 2012.sql | 7 +++++++ ...rs attributed to a salesman in New york.sql | 7 +++++++ ...e salesmen servicing customers in Paris.sql | 7 +++++++ ... 2001 bellow the salesman ID of Mc Lyon.sql | 7 +++++++ ...rs with grades above New York's average.sql | 7 +++++++ ...ustomers with orders on October 5, 2012.sql | 5 +++++ ...yee id, and job title for all employees.sql | 13 +++++++++++++ ...e employee whose ID 134 and works there.sql | 11 +++++++++++ ...tments which located in the city London.sql | 11 +++++++++++ ... Id is equal to the Id for the location.sql | 12 ++++++++++++ ... which starting salary is at least 8000.sql | 9 +++++++++ ... last name, and department code for all.sql | 11 +++++++++++ ...y and department ID for those employees.sql | 13 +++++++++++++ ...e employees who work in that department.sql | 9 +++++++++ ...salary, and also work at the department.sql | 13 +++++++++++++ ...m salary of a department which ID is 70.sql | 10 ++++++++++ ...m salary of a department which ID is 40.sql | 10 ++++++++++ ...m salary of a department which ID is 40.sql | 9 +++++++++ ...ees whose salary is equal to the salary.sql | 10 ++++++++++ ... who is supervising 4 or more employees.sql | 10 ++++++++++ ...ired after the employee whose ID is 165.sql | 9 +++++++++ ...ry is 7000 or above for those employees.sql | 14 ++++++++++++++ ...partments located in the United Kingdom.sql | 16 ++++++++++++++++ ... determine who earns more than Mr. Ozer.sql | 10 ++++++++++ ...y id who earn the second highest salary.sql | 14 ++++++++++++++ ...person id is 3000 and 121 respectively..sql | 7 +++++++ ... person id is 3000 and 121 respectively.sql | 6 ++++++ ... departments where some employees works.sql | 9 +++++++++ ...n the range of smallest salary and 2500.sql | 7 +++++++ ...alary is within the range 1000 and 3000.sql | 5 +++++ ...ob title for all employees whose salary.sql | 11 +++++++++++ ...contains at least one salaried employee.sql | 11 +++++++++++ ...s who earn more than the average salary.sql | 8 ++++++++ ... for those employees whose job title is.sql | 12 ++++++++++++ ... of all employees) and the SalaryStatus.sql | 14 ++++++++++++++ ...Status column with a title HIGH and LOW.sql | 12 ++++++++++++ ...ame and last name ), salary, department.sql | 13 +++++++++++++ ...ry of all employees who report to Payam.sql | 9 +++++++++ ... any existence of those employees whose.sql | 10 ++++++++++ ...same department as Clara. Exclude Clara.sql | 11 +++++++++++ ...th any employee whose name contains a T.sql | 10 ++++++++++ ...loyees whose salary is smaller than any.sql | 12 ++++++++++++ ... for all employees whose salary is more.sql | 11 +++++++++++ ...alary than the employee whose id is 163.sql | 9 +++++++++ ... works for a department based in the US.sql | 15 +++++++++++++++ ...e details of employees who are managers.sql | 9 +++++++++ ...ls of employees who manage a department.sql | 7 +++++++ ...d who work in any of the IT departments.sql | 12 ++++++++++++ ... of their departments total salary bill.sql | 10 ++++++++++ ...d is any of the number 134, 159 and 183.sql | 6 ++++++ ... one or more employees assigned to them.sql | 8 ++++++++ ...all employees in the Finance department.sql | 6 ++++++ ...salesmen and customer located in London.sql | 8 ++++++++ ...play distinct salesman and their cities.sql | 6 ++++++ ...ved in this inventory management system.sql | 6 ++++++ ...argest and smallest orders on each date.sql | 16 ++++++++++++++++ ...umber in smallest to the largest number.sql | 18 ++++++++++++++++++ ...n their cities, as well as whose who do.sql | 12 ++++++++++++ ...n was matched to a customer in his city.sql | 12 ++++++++++++ .... Those with a rating of 300 or greater.sql | 9 +++++++++ .... Put the results in alphabetical order.sql | 16 ++++++++++++++++ .../1. How to create a user on localhost.sql | 11 +++++++++++ ... permissions granted to a specific user.sql | 4 ++++ ...ivileges that the MySQL server supports.sql | 4 ++++ ...a specific number of queries in an hour.sql | 7 +++++++ ...a specific number of queries in an hour.sql | 4 ++++ sql/UserManagement/14. How to delete user.sql | 4 ++++ .../15. How to rename a user.sql | 5 +++++ ...reate a user and granting no privileges.sql | 4 ++++ ... for an IP address other than localhost.sql | 12 ++++++++++++ ...to a user to select only from localhost.sql | 12 ++++++++++++ ... create temporary tables from localhost.sql | 13 +++++++++++++ ...d create temporary tables from any host.sql | 13 +++++++++++++ ...t but to a specific table of a database.sql | 13 +++++++++++++ ... privileges to a user from all machines.sql | 13 +++++++++++++ ...ow to revoke all privileges from a user.sql | 11 +++++++++++ ...o revoke specific privilege from a user.sql | 12 ++++++++++++ ...e salesmen belongs to the city New York.sql | 5 +++++ ...the number of the salesman in each city.sql | 5 +++++ ...her name. (Assume all names are unique).sql | 0 ...for each salesman after his or her name.sql | 7 +++++++ ...h salesman with more than one customers.sql | 8 ++++++++ ... all matches of customers with salesman.sql | 6 ++++++ ... shows the number of orders in each day.sql | 5 +++++ ...who issued orders on October 10th, 2012.sql | 8 ++++++++ ...August 17th, 2012 or October 10th, 2012.sql | 6 ++++++ ...with columns salesman_id, name and city.sql | 4 ++++ ...o achieved the commission more than 13%.sql | 14 ++++++++++++++ ...tomers we have at each level of a grade.sql | 5 +++++ ...s ordering, number of salesmen attached.sql | 7 +++++++ ...order the salesman and customer by name.sql | 6 ++++++ ...ustomer with the highest order of a day.sql | 9 +++++++++ ...highest order at least 3 times on a day.sql | 9 +++++++++ ...he customers who have the highest grade.sql | 7 +++++++ ...se names are ending with the letter 'n'.sql | 4 ++++ ... who does not get any grade except NULL.sql | 4 ++++ ...tion who gets a grade except NULL value.sql | 4 ++++ ...rs whose name begin with the letter 'B'.sql | 4 ++++ ...he character ( % ) in its column 'col1'.sql | 4 ++++ ... escape character in its column 'col1'.sql | 5 +++++ ...r underscore ( _ ) in its column 'col1'.sql | 5 +++++ ...ontain the string in its column 'col1'.sql | 4 ++++ ...he character ( % ) in its column 'col1'.sql | 5 +++++ ...r underscore ( _ ) in its column 'col1'.sql | 5 +++++ ... escape character in its column 'col1'.sql | 5 +++++ ...ntain the string in its column 'col1'..sql | 0 ...ontain the string in its column 'col1'.sql | 5 +++++ ...come from the city either Paris or Rome.sql | 4 ++++ ...mission within a range of 0.12 and 0.14.sql | 4 ++++ ...ter is 'N' and the 4th character is 'l'.sql | 5 +++++ ...ame started with any latter 'A' and 'L'.sql | 4 ++++ ...ther than any latter within 'A' and 'L'.sql | 5 +++++ ...yees whose last name begins with an 'D'.sql | 4 ++++ ...s from any of the cities Paris and Rome.sql | 4 ++++ ... leave other cities than Paris and Rome.sql | 4 ++++ ...ue is within any of 3007, 3008 and 3009.sql | 4 ++++ 354 files changed, 2466 insertions(+) create mode 100644 sql/AggregateFunctions/Write a SQL query to calculate the average price of all the products.sql create mode 100644 sql/AggregateFunctions/Write a SQL query to display the average price of each company's products, along with their code.sql create mode 100644 sql/AggregateFunctions/Write a SQL query to find the number of products with a price more than or equal to Rs.350.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement find the number of customers who gets at least a gradation for hisor her performance..sql create mode 100644 sql/AggregateFunctions/Write a SQL statement that counts all orders for a date August 17th, 2012.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement that counts the number of different non NULL city values for salesmen.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to display customer details (ID and purchase amount) whose and highest purchase amount is more than 1000..sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the average purchase amount of all orders.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount on a date '2012-08-17' for each salesman with their ID.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount ordered by the each customer on a particular date with their ID, order date and highest purchase amount.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount ordered by the each customer with their ID and highest purchase amount.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID amount in a day is within the list 2000, 3000, 5760 and 6000..sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID and order date, for only those customers who have highest purchase amount in a day is more than 2000.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID and order date, for those customers who have a higher purchase.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID, for only those customers whose ID is within the range 3002 and 3007.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID, for only those salesmen whose ID is within the range 5003 and 5008.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the number of salesmen currently listing for all of their customers.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to find the total purchase amount for all orders.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to know how many customers have listed their names.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to know the maximum purchase amount of all the orders.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement to know the minimum purchase amount of all the orders.sql create mode 100644 sql/AggregateFunctions/Write a SQL statement which selects the highest grade for each of the cities of the customers.sql create mode 100644 sql/AggregateFunctions/Write a query in SQL to find the number of employees in each department along with the department code.sql create mode 100644 sql/AggregateFunctions/Write a query in SQL to find the sum of the allotment amount of all departments.sql create mode 100644 sql/AggregateFunctions/Write a query that counts the number of salesmen with their order date and ID registering orders for each day.sql create mode 100644 sql/BooleanRelationalOperators/Display all in reverse, where order dates equal to a specified date or customer id greater than a specified number and purchase amount less than a specified amount..sql create mode 100644 sql/BooleanRelationalOperators/Display all in reverse, where order dates equal to a specified date or customer id greater than a specified number and purchase amount less than a specified amount.sql create mode 100644 sql/BooleanRelationalOperators/Write a SQL query to display all orders where purchase amount less than a specified amount or order date and customer_id must not.sql create mode 100644 sql/BooleanRelationalOperators/Write a SQL query to display order number, purchase amount, achived, the unachieved percentage for those order which exceeds the 50% of the target value of 6000.sql create mode 100644 sql/BooleanRelationalOperators/Write a SQL query to display those customers who are neither belongs to the city New York nor grade value is more than 100.sql create mode 100644 sql/BooleanRelationalOperators/Write a SQL statement to display all customers, who are either belongs to the city New York or had a grade above 100.sql create mode 100644 sql/BooleanRelationalOperators/Write a SQL statement to display all the customers, who are either belongs to the city New York or not had a grade above 100.sql create mode 100644 sql/BooleanRelationalOperators/Write a SQL statement to display either those orders which are not issued on date 2012-09-10 and issued by the salesman whose ID is 505 and below or t.sql create mode 100644 sql/BooleanRelationalOperators/Write a SQL statement to display salesman_id, name, city and commission who gets the commission within the range more than 0.10% and less than 0.12%.sql create mode 100644 sql/BooleanRelationalOperators/Write a query in SQL to display all the data of employees that work in department 47 or department 63.sql create mode 100644 sql/BooleanRelationalOperators/Write a query in SQL to find the data of employees whose last name is Dosni or Mardy.sql create mode 100644 sql/BooleanRelationalOperators/Write a query statement to display all customers in New York who have a grade value above 100.sql create mode 100644 sql/BooleanRelationalOperators/Write a query to display all customers with a grade above 100.sql create mode 100644 sql/FormattingOutput/Write a SQL statement to arrange the orders according to the order_date in such a manner that.sql create mode 100644 sql/FormattingOutput/Write a SQL statement to display customer name, city and grade in such a manner that, the customer holding highest grade will come first.sql create mode 100644 sql/FormattingOutput/Write a SQL statement to display the commission with the percent sign ( % ) with salesman ID, name and city columns for all the salesmen.sql create mode 100644 sql/FormattingOutput/Write a SQL statement to display the customer name, city, and grade, etc. and the display will be arranged according to the smallest customer ID.sql create mode 100644 sql/FormattingOutput/Write a SQL statement to display the orders with all information in such a manner that, the older order date will come first and the highest purchase amount of same day will come first.sql create mode 100644 sql/FormattingOutput/Write a SQL statement to find out the number of orders booked for each day and display it in such a format like.sql create mode 100644 sql/FormattingOutput/Write a SQL statement to make a report with customer ID in such a manner that, the largest number of orders booked by the customer will come first.sql create mode 100644 sql/FormattingOutput/Write a query to display the orders according to the order number arranged by ascending order.sql create mode 100644 sql/JoinHRDatabase/1. Write a query in SQL to display the first name, last name, department number, and department name for each employee.sql create mode 100644 sql/JoinHRDatabase/10. Write a query in SQL to display the first name, last name, department number and name, for all employees who have or have not any department.sql create mode 100644 sql/JoinHRDatabase/11. Write a query in SQL to display the first name of all employees and the first name of their manager including those who does not working under any manager.sql create mode 100644 sql/JoinHRDatabase/13. Write a query in SQL to display the job title, department name, full name (first and last name ) of employee, and starting date for all the jobs.sql create mode 100644 sql/JoinHRDatabase/14. Write a query in SQL to display job title, full name (first and last name ) of employee, and the difference between maximum salary for the job and salary of the employee.sql create mode 100644 sql/JoinHRDatabase/15. Write a query in SQL to display the name of the department, average salary and number of employees working in that department who got commission.sql create mode 100644 sql/JoinHRDatabase/17. Write a query in SQL to display the name of the country, city, and the departments which are running there.sql create mode 100644 sql/JoinHRDatabase/18. Write a query in SQL to display department name and the full name (first and last name) of the manager.sql create mode 100644 sql/JoinHRDatabase/19. Write a query in SQL to display job title and average salary of employees.sql create mode 100644 sql/JoinHRDatabase/2. Write a query in SQL to display the first and last name, department, city, and state province for each employee.sql create mode 100644 sql/JoinHRDatabase/20. Write a query in SQL to display the details of jobs which was done by any of the employees who is presently earning a salary on and above 12000.sql create mode 100644 sql/JoinHRDatabase/21. Write a query in SQL to display the country name, city, and number of those departments where at leaste 2 employees are working.sql create mode 100644 sql/JoinHRDatabase/22. Write a query in SQL to display the department name, full name (first and last name) of manager, and their city.sql create mode 100644 sql/JoinHRDatabase/23. Write a query in SQL to display the employee ID, job name, number of days worked in for all those jobs in department 80.sql create mode 100644 sql/JoinHRDatabase/24. Write a query in SQL to display the full name (first and last name), and salary of those employees who working in any department located in London.sql create mode 100644 sql/JoinHRDatabase/25. Write a query in SQL to display full name(first and last name), job title, starting and ending date of last jobs for those employees with worked without a commission percentage.sql create mode 100644 sql/JoinHRDatabase/26. Write a query in SQL to display the department name and number of employees in each of the department.sql create mode 100644 sql/JoinHRDatabase/3. Write a query in SQL to display the first name, last name, salary, and job grade for all employees.sql create mode 100644 sql/JoinHRDatabase/4. Write a query in SQL to display the first name, last name, department number and department name, for all employees for departments 80 or 40.sql create mode 100644 sql/JoinHRDatabase/5. Write a query in SQL to display those employees who contain a letter z to their first name and also display their last name, department, city, and state province.sql create mode 100644 sql/JoinHRDatabase/6. Write a query in SQL to display all departments including those where does not have any employee.sql create mode 100644 sql/JoinHRDatabase/7. Write a query in SQL to display the first and last name and salary for those employees who earn less than the employee earn whose number is 182.sql create mode 100644 sql/JoinHRDatabase/8. Write a query in SQL to display the first name of all employees including the first name of their manager.sql create mode 100644 sql/JoinHRDatabase/9. Write a query in SQL to display the department name, city, and state province for each department.sql create mode 100644 sql/Joins/2Write a SQL query to display the average price of items of each company, showing the name of the company.sql create mode 100644 sql/Joins/3Write a SQL query to display the average price of items of each company, showing the name of the company.sql create mode 100644 sql/Joins/Write a SQL query to display all the data from the item_mast, including all the data for each item's producer company.sql create mode 100644 sql/Joins/Write a SQL query to display the average price of items of each company, showing the name of the company.sql create mode 100644 sql/Joins/Write a SQL query to display the item name, price, and company name of all the products.sql create mode 100644 sql/Joins/Write a SQL statement to find the details of a order i.e. order number, order date, amount of order, which customer gives the order and which salesman works for that customer.sql create mode 100644 sql/Joins/Write a SQL statement to find the list of customers who appointed a salesman for their jobs who does not live in the same city where their customer lives, and gets a commission is above 12%.sql create mode 100644 sql/Joins/Write a SQL statement to find the list of customers who appointed a salesman for their jobs who gets a commission from the company is more than 12%.sql create mode 100644 sql/Joins/Write a SQL statement to know which salesman are working for which customer.sql create mode 100644 sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for that customer who belongs to a city.sql create mode 100644 sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for those salesmen who belongs.sql create mode 100644 sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for those salesmen who must belong a city.sql create mode 100644 sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman.sql create mode 100644 sql/Joins/Write a SQL statement to make a join on the tables salesman, customer and orders in such a form that the same column of each table will appear once and only the relational rows will come.sql create mode 100644 sql/Joins/Write a SQL statement to make a list for the salesmen who either work for one or more customers or yet to join any of the customer.sql create mode 100644 sql/Joins/Write a SQL statement to make a list for the salesmen who works either for one or more customer or not yet join under any of the customers.sql create mode 100644 sql/Joins/Write a SQL statement to make a list in ascending order for the customer who holds a grade less than 300 and works either through a salesman or by own.sql create mode 100644 sql/Joins/Write a SQL statement to make a list in ascending order for the customer who works either through a salesman or by own.sql create mode 100644 sql/Joins/Write a SQL statement to make a list in ascending order for the salesmen who works either for one or more customer or not yet join under any of the customers.sql create mode 100644 sql/Joins/Write a SQL statement to make a list with order no, purchase amount, customer name and their cities for those orders which order amount between 500 and 2000.sql create mode 100644 sql/Joins/Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for only those customers on the list who must have a grade and placed.sql create mode 100644 sql/Joins/Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for those customers from the existing list who placed one or more orders.sql create mode 100644 sql/Joins/Write a SQL statement to make a report with customer name, city, order number, order date, and order amount in ascending order according to the order date.sql create mode 100644 sql/Joins/Write a SQL statement to make a report with customer name, city, order number, order date, order amount salesman name and commission to find that either any of the existing customers.sql create mode 100644 sql/Joins/Write a SQL statement to prepare a list with salesman name, customer name and their cities for the salesmen and customer who belongs to the same city.sql create mode 100644 sql/QueryMultipleTables/Write a SQL statement that finds out each order number followed by the name of the customers who made the order.sql create mode 100644 sql/QueryMultipleTables/Write a SQL statement that produces all orders with the order number, customer name, commission rate and earned commission amount for those customers.sql create mode 100644 sql/QueryMultipleTables/Write a SQL statement that shorts out the customer and their grade who made an order. Each of the customers must have a grade and served.sql create mode 100644 sql/QueryMultipleTables/Write a SQL statement to find the names of all customers along with the salesmen who works for them.sql create mode 100644 sql/QueryMultipleTables/Write a query to find those customers with their name and those salesmen with their name and city who lives in the same city.sql create mode 100644 sql/README.md create mode 100644 sql/RetrieveFromTables/Write a SQL query to calculate the average price of all products of the manufacturer which code is l6.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to display the Nobel prizes for 1970.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to display the average price of the items for each company, showing only the company code.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to display the year and subject that won 'Dennis Gabor' his prize.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to find all details of the prize won by Johannes Georg Bednorz.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to find all the details of 1970 winners by the ordered to subject and winner name; but the list contain the subject Economics and Chemistry at last.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to find all the products with a price between Rs.200 and Rs.600.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to find the item name and price in Rs.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to find the name and price of the cheapest item.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to give the name of the 'Physics' winners since the year 1950.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to know the winner of the 1971 prize for Literature.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to show all details of the Prime Ministerial winners after 1972 of Menachem Begin and Yitzhak Rabin.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to show all the details (year, subject, winner, country ) of the Chemistry prize winners between the year 1965 to 1975 inclusive.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to show all the details of the winners with first name Louis.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to show all the winners in Physics for 1970 together with the winner of Economics for 1971.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to show all the winners of nobel prize in the year 1970 except the subject Physiology and Economics.sql create mode 100644 sql/RetrieveFromTables/Write a SQL query to show the winners of a 'Physiology' prize in an early year before 1971 together with winners of a 'Peace' prize in a later year on and after the 1974.sql create mode 100644 sql/RetrieveFromTables/Write a SQL statement to display all the information for those customers with a grade of 200.sql create mode 100644 sql/RetrieveFromTables/Write a query in SQL to display all the data of employees that work in the department 57.sql create mode 100644 sql/RetrieveFromTables/Write a query in SQL to find the data of employees whose last name is 'Snares'.sql create mode 100644 sql/RetrieveFromTables/Write a query in SQL to find the last name of all employees, without duplicates.sql create mode 100644 sql/RetrieveFromTables/Write a query to display a string This is SQL Exercise, Practice and Solution.sql create mode 100644 sql/RetrieveFromTables/Write a query to display all the columns from salesman table.sql create mode 100644 sql/RetrieveFromTables/Write a query to display names and city of salesman, who belongs to the city of Paris.sql create mode 100644 sql/RetrieveFromTables/Write a query to display only name and commission from table salesman.sql create mode 100644 sql/RetrieveFromTables/Write a query to display salesman_id, salesman name, order date, order no, and purchase amount from orders table.sql create mode 100644 sql/RetrieveFromTables/Write a query to display sum of two numbers 10 and 15.sql create mode 100644 sql/RetrieveFromTables/Write a query to display the result of an arithmetic simplification.sql create mode 100644 sql/RetrieveFromTables/Write a query to display three numbers in three columns.sql create mode 100644 sql/RetrieveFromTables/Write a query which will retrieve the values of salesman id of all salesmen, getting orders from the customers in orders table without any repeats.sql create mode 100644 sql/RetrieveFromTables/Write a sql query to display the order number followed by order date and the purchase amount for each order which will be delivered by the salesman who is holding the ID 5001.sql create mode 100644 sql/SQLMovieDatabase/1. Write a query in SQL to find the name and year of the movies.sql create mode 100644 sql/SQLMovieDatabase/10. Write a query in SQL to find the list of all those movies with year which include the words Boogie Nights.sql create mode 100644 sql/SQLMovieDatabase/11. Write a query in SQL to find the ID number for the actor whose first name is 'Woody' and the last name is 'Allen'.sql create mode 100644 sql/SQLMovieDatabase/12. Write a query in SQL to list all the information of the actors who played a role in the movie 'Annie Hall'.sql create mode 100644 sql/SQLMovieDatabase/13. Write a query in SQL to list the first and last names of all the actors who were cast in the movie 'Annie Hall', and the roles they played in that production.sql create mode 100644 sql/SQLMovieDatabase/14. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a role for 'Eyes Wide Shut'.sql create mode 100644 sql/SQLMovieDatabase/15. Write a query in SQL to find the name of the director (first and last names) who directed a movie that casted a role for 'Eyes Wide Shut'.sql create mode 100644 sql/SQLMovieDatabase/16. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a role as Sean Maguire.sql create mode 100644 sql/SQLMovieDatabase/17. Write a query in SQL to list all the actors who acted in a movie before 1990 and also in a movie after 2000.sql create mode 100644 sql/SQLMovieDatabase/18. Write a query in SQL to list first and last name of all the directors with number of genres movies they directed with genres name, and arranged.sql create mode 100644 sql/SQLMovieDatabase/19. Write a query in SQL to list all the movies with year and genres.sql create mode 100644 sql/SQLMovieDatabase/2. Write a query in SQL to find the year when the movie American Beauty released.sql create mode 100644 sql/SQLMovieDatabase/20. Write a query in SQL to list all the movies with year, genres, and name of the director.sql create mode 100644 sql/SQLMovieDatabase/21. Write a query in SQL to list all the movies which released in the country other than UK.sql create mode 100644 sql/SQLMovieDatabase/22. Write a query in SQL to list all the movies with title, year, date of release, movie duration, and first and last name of the director which released before 1st January 1998.sql create mode 100644 sql/SQLMovieDatabase/23. Write a query in SQL to compute a report which contain the genres of those movies with their average time and number of movies for each genres.sql create mode 100644 sql/SQLMovieDatabase/24. Write a query in SQL to find those lowest duration movies along with the year, director's name, actor's name and his or her role in that production.sql create mode 100644 sql/SQLMovieDatabase/25. Write a query in SQL to find the movie title, year, date of release, director and actor for those movies which reviewer is unknown.sql create mode 100644 sql/SQLMovieDatabase/26. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.sql create mode 100644 sql/SQLMovieDatabase/27. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.sql create mode 100644 sql/SQLMovieDatabase/28. Write a query in SQL to find the titles of all movies that have no ratings.sql create mode 100644 sql/SQLMovieDatabase/29. Write a query in SQL to find the names of all reviewers who have ratings with a NULL value.sql create mode 100644 sql/SQLMovieDatabase/3. Write a query in SQL to find the movie which was released in the year 1999.sql create mode 100644 sql/SQLMovieDatabase/30. Write a query in SQL to return the reviewer name, movie title, and stars for those movies which reviewed by a reviewer and must be rated.sql create mode 100644 sql/SQLMovieDatabase/31. Write a query in SQL to find the reviewer's name and the title of the movie for those reviewers who rated more than one movies.sql create mode 100644 sql/SQLMovieDatabase/32. Write a query in SQL to find the movie title, and the highest number of stars that movie received and arranged the result according to the group.sql create mode 100644 sql/SQLMovieDatabase/33. Write a query in SQL to find the names of all reviewers who rated the movie American Beauty.sql create mode 100644 sql/SQLMovieDatabase/34. Write a query in SQL to find the titles of all movies which have been reviewed by anybody except by Paul Monks.sql create mode 100644 sql/SQLMovieDatabase/35. Write a query in SQL to return the reviewer name, movie title, and number of stars for those movies which rating is the lowest one.sql create mode 100644 sql/SQLMovieDatabase/36. Write a query in SQL to find the titles of all movies directed by James Cameron.sql create mode 100644 sql/SQLMovieDatabase/37. Write a query in SQL to find all the years which produced a movie that received a rating of 3 or 4, and sort the result in increasing order.sql create mode 100644 sql/SQLMovieDatabase/38. Write a query in SQL to return the reviewer name, movie title, and stars in an order that reviewer name will come first, then by movie title, and lastly by number of stars.sql create mode 100644 sql/SQLMovieDatabase/4. Write a query in SQL to find the movies which was released before 1998.sql create mode 100644 sql/SQLMovieDatabase/40. Write a query in SQL to find the director's first and last name together with the title of the movie(s) they directed and received the rating.sql create mode 100644 sql/SQLMovieDatabase/41. Write a query in SQL to find the name of those movies where one or more actors acted in two or more movies.sql create mode 100644 sql/SQLMovieDatabase/42. Write a query in SQL to find the movie title, actor first and last name, and the role for those movies where one or more actors acted in two or more movies.sql create mode 100644 sql/SQLMovieDatabase/43. Write a query in SQL to find the first and last name of a director and the movie he or she directed, and the actress appeared which first name was Claire.sql create mode 100644 sql/SQLMovieDatabase/44. Write a query in SQL to find the first and last name of an actor with their role in the movie which was also directed by themselve.sql create mode 100644 sql/SQLMovieDatabase/45. Write a query in SQL to find the cast list for the movie Chinatown.sql create mode 100644 sql/SQLMovieDatabase/46. Write a query in SQL to find the movie in which the actor appeared whose first and last name are 'Harrison' and 'Ford'.sql create mode 100644 sql/SQLMovieDatabase/47. Write a query in SQL to find the highest-rated movie, and report its title, year, rating, and releasing country.sql create mode 100644 sql/SQLMovieDatabase/48. Write a query in SQL to find the highest-rated Mystery movie, and report the title, year, and rating.sql create mode 100644 sql/SQLMovieDatabase/49. Write a query in SQL to generate a report which shows the year when most of the Mystery movies produces, and number of movies and their average rating.sql create mode 100644 sql/SQLMovieDatabase/5. Write a query in SQL to return the name of all reviewers and name of movies together in a single list, alphabetically.sql create mode 100644 sql/SQLMovieDatabase/6. Write a query in SQL to find the name of all reviewers who have rated 7 or more stars to their rating.sql create mode 100644 sql/SQLMovieDatabase/7. Write a query in SQL to find the titles of all movies that have no ratings.sql create mode 100644 sql/SQLMovieDatabase/8. Write a query in SQL to find the name of all reviewers who have rated their ratings with a NULL value.sql create mode 100644 sql/SQLMovieDatabase/9. Write a query in SQL to find the titles of the movies with ID 905, 907, 917.sql create mode 100644 sql/SortingFilteringHRDatabase/1. Write a query in SQL to display the full name (first and last name), and salary for those employees who earn below 6000.sql create mode 100644 sql/SortingFilteringHRDatabase/10. Write a query in SQL to display the first and last name, and salary for those employees whose first name is ending with the letter m.sql create mode 100644 sql/SortingFilteringHRDatabase/11. Write a query in SQL to display the full name (first and last) name, and salary, for all employees whose salary is out of the range 7000 and 15000.sql create mode 100644 sql/SortingFilteringHRDatabase/13. Write a query in SQL to display the the full name (first and last name), and department number for those employees who works either in department 70 or 90.sql create mode 100644 sql/SortingFilteringHRDatabase/14. Write a query in SQL to display the full name (first and last name), salary, and manager number for those employees.sql create mode 100644 sql/SortingFilteringHRDatabase/15. Write a query in SQL to display all the information from Employees table for those employees who was hired before June 21st, 1987.sql create mode 100644 sql/SortingFilteringHRDatabase/16. Write a query in SQL to display the first and last name, email, salary and manager ID, for those employees whose managers are hold the ID 120, 103 or 145.sql create mode 100644 sql/SortingFilteringHRDatabase/18. Write a query in SQL to display the full name (first name and last name), hire date, commission percentage.sql create mode 100644 sql/SortingFilteringHRDatabase/19. Write a query in SQL to display the first and last name, and department number for those employees who holds a letter.sql create mode 100644 sql/SortingFilteringHRDatabase/2. Write a query in SQL to display the first and last_name, department number and salary for those employees who earn more than 8000.sql create mode 100644 sql/SortingFilteringHRDatabase/20. Write a query in SQL to display the employee ID, first name, job id, and department number for those employees who is working except the departments 50,30 and 80.sql create mode 100644 sql/SortingFilteringHRDatabase/21. Write a query in SQL to display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90.sql create mode 100644 sql/SortingFilteringHRDatabase/22. Write a query in SQL to display the ID for those employees who did two or more jobs in the past.sql create mode 100644 sql/SortingFilteringHRDatabase/23. Write a query in SQL to display job ID, number of employees, sum of salary, and difference between highest salary and lowest salary for a job.sql create mode 100644 sql/SortingFilteringHRDatabase/24. Write a query in SQL to display job ID for those jobs that were done by two or more for more than 300 days.sql create mode 100644 sql/SortingFilteringHRDatabase/25. Write a query in SQL to display the country ID and number of cities in that country we have.sql create mode 100644 sql/SortingFilteringHRDatabase/26. Write a query in SQL to display the manager ID and number of employees managed by the manager.sql create mode 100644 sql/SortingFilteringHRDatabase/27. Write a query in SQL to display the details of jobs in descending sequence on job title.sql create mode 100644 sql/SortingFilteringHRDatabase/28. Write a query in SQL to display the first and last name and date of joining of the employees.sql create mode 100644 sql/SortingFilteringHRDatabase/29. Write a query in SQL to display the average salary of employees for each department who gets a commission percentage.sql create mode 100644 sql/SortingFilteringHRDatabase/3. Write a query in SQL to display the first and last name, and department number for all employees whose last name is McEwen.sql create mode 100644 sql/SortingFilteringHRDatabase/30. Write a query in SQL to display those departments where any manager is managing 4 or more employees.sql create mode 100644 sql/SortingFilteringHRDatabase/31. Write a query in SQL to display those departments where more than ten employees work.sql create mode 100644 sql/SortingFilteringHRDatabase/32. Write a query in SQL to display the employee ID and the date on which he ended his previous job.sql create mode 100644 sql/SortingFilteringHRDatabase/34. Write a query in SQL to display the job ID for those jobs which average salary is above 8000.sql create mode 100644 sql/SortingFilteringHRDatabase/35. Write a query in SQL to display job Title, the difference between minimum and maximum salaries for those jobs which max salary within the range 12000 to 18000.sql create mode 100644 sql/SortingFilteringHRDatabase/36. Write a query in SQL to display all those employees whose first name or last name starts with the letter D.sql create mode 100644 sql/SortingFilteringHRDatabase/37. Write a query in SQL to display the details of jobs which minimum salary is greater than 9000.sql create mode 100644 sql/SortingFilteringHRDatabase/38. Write a query in SQL to display those employees who joined after 7th September, 1987.sql create mode 100644 sql/SortingFilteringHRDatabase/4. Write a query in SQL to display all the information for all employees without any department number.sql create mode 100644 sql/SortingFilteringHRDatabase/5. Write a query in SQL to display all the information about the department Marketing.sql create mode 100644 sql/SortingFilteringHRDatabase/6. Write a query in SQL to display the full name (first and last), hire date, salary, and department number for those employees.sql create mode 100644 sql/SortingFilteringHRDatabase/7. Write a query in SQL to display all the information of employees whose salary is in the range of 8000 and 12000 and commission is not null.sql create mode 100644 sql/SortingFilteringHRDatabase/8. Write a query in SQL to display the full name (first and last name), and salary for all employees who does not earn any commission.sql create mode 100644 sql/SortingFilteringHRDatabase/9. Write a query in SQL to display the full name (first and last), the phone number and email separated.sql create mode 100644 sql/Subqueries/1. Write a query to display all the orders from the orders table issued by the salesman 'Paul Adam'.sql create mode 100644 sql/Subqueries/10. Write a query to display all the customers with orders issued on date 17th August, 2012.sql create mode 100644 sql/Subqueries/11. Write a query to find the name and numbers of all salesmen who had more than one customer.sql create mode 100644 sql/Subqueries/12. Write a query to find all orders with order amounts which are above-average amounts for their customers.sql create mode 100644 sql/Subqueries/13. Write a queries to find all orders with order amounts which are on or above-average amounts for their customers.sql create mode 100644 sql/Subqueries/15. Write a query to extract the data from the customer table if and only if one or more of the customers in the customer table are located in London.sql create mode 100644 sql/Subqueries/16. Write a query to find the salesmen who have multiple customers.sql create mode 100644 sql/Subqueries/17. Write a query to find all the salesmen who worked for only one customer.sql create mode 100644 sql/Subqueries/18. Write a query that extract the rows of all salesmen who have customers with more than one orders.sql create mode 100644 sql/Subqueries/19. Write a query to find a salesman with customers located in their cities.sql create mode 100644 sql/Subqueries/2. Write a query to display all the orders for the salesman who belongs to the city London.sql create mode 100644 sql/Subqueries/20. Write a query to find all the salesmen for whom there are customers that follow them.sql create mode 100644 sql/Subqueries/21. Write a query to display the salesmen which name are alphabetically lower than the name of the customers.sql create mode 100644 sql/Subqueries/22. Write a query to display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York.sql create mode 100644 sql/Subqueries/23. Write a query to display all the orders that had amounts that were greater than at least one of the orders from October 9th 2012.sql create mode 100644 sql/Subqueries/24. Write a query to find all orders with an amount smaller than any amount for a customer in London.sql create mode 100644 sql/Subqueries/25. Write a query to display all orders with an amount smaller than any amount for a customer in London.sql create mode 100644 sql/Subqueries/26. Write a query to display only those customers whose grade are, in fact, higher than every customer in New York.sql create mode 100644 sql/Subqueries/27. Write a query to find only those customers whose grade are, higher than every customer to the city New York.sql create mode 100644 sql/Subqueries/28.Write a query to get all the information for those customers whose grade is not as the grade of customer who belongs to the city London.sql create mode 100644 sql/Subqueries/29. Write a query to find all those customers whose grade are not as the grade, belongs to the city Paris.sql create mode 100644 sql/Subqueries/3. Write a query to find all the orders issued against the salesman who works for customer whose id is 3007.sql create mode 100644 sql/Subqueries/30. Write a query to find all those customers who hold a different grade than any customer of the city Dallas.sql create mode 100644 sql/Subqueries/4. Write a query to display all the orders which values are greater than the average order value for 10th October 2012.sql create mode 100644 sql/Subqueries/5. Write a query to find all orders attributed to a salesman in New york.sql create mode 100644 sql/Subqueries/6. Write a query to display the commission of all the salesmen servicing customers in Paris.sql create mode 100644 sql/Subqueries/7. Write a query to display all the customers whose id is 2001 bellow the salesman ID of Mc Lyon.sql create mode 100644 sql/Subqueries/8. Write a query to counts the customers with grades above New York's average.sql create mode 100644 sql/Subqueries/9. Write a query to display all customers with orders on October 5, 2012.sql create mode 100644 sql/SubqueriesHRDatabase/Display the employee name( first name and last name ), employee id, and job title for all employees.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the city of the employee whose ID 134 and works there.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the department code and name for all departments which located in the city London.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the department name and Id for all departments where they located, that Id is equal to the Id for the location.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the detail information of those departments which starting salary is at least 8000.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, and department code for all.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary and department ID for those employees.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for all those employees who work in that department.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than the average salary, and also work at the department.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than the minimum salary of a department which ID is 70.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the maximum salary of a department which ID is 40.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the minimum salary of a department which ID is 40.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees whose salary is equal to the salary.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the full name (first and last name) of manager who is supervising 4 or more employees.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the full name,email, and designation for all those employees who was hired after the employee whose ID is 165.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query in SQL to display the the details of those departments which max salary is 7000 or above for those employees.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query that will identify all employees who work in departments located in the United Kingdom.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to determine who earns more than Mr. Ozer.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display all the information for those employees whose id is any id who earn the second highest salary.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 respectively..sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 respectively.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display all the information of the employees who does not work in those departments where some employees works.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display all the information of the employees whose salary if within the range of smallest salary and 2500.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display all the information of the employees whose salary is within the range 1000 and 3000.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the ( first name and last name ) and job title for all employees whose salary.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the department id and the total salary for those departments which contains at least one salaried employee.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee id, employee name (first name and last name ) for all employees who earn more than the average salary.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ) and the job id column with a modified title SALESMAN for those employees whose job title is.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), SalaryDrawn, AvgCompare (salary - the average salary of all employees) and the SalaryStatus.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), salary and the SalaryStatus column with a title HIGH and LOW.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), salary, department.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee name ( first name and last name ), employee id and salary of all employees who report to Payam.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee name( first name and last name ) and department for all employees for any existence of those employees whose.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee name( first name and last name ) and hiredate for all employees in the same department as Clara. Exclude Clara.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee number and name( first name and last name ) for all employees who work in a department with any employee whose name contains a T.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee number, name ob title for all employees whose salary is smaller than any.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the employee number, name( first name and last name ) and job title for all employees whose salary is more.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to display the name ( first name and last name ) for those employees who gets more salary than the employee whose id is 163.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to find out which employees have a manager who works for a department based in the US.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to get the details of employees who are managers.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to get the details of employees who manage a department.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query to identify all the employees who earn more than the average and who work in any of the IT departments.sql create mode 100644 sql/SubqueriesHRDatabase/Write a query which is looking for the names of all employees whose salary is greater than 50 of their departments total salary bill.sql create mode 100644 sql/SubqueriesHRDatabase/Write a statement to display all the information of an employee whose id is any of the number 134, 159 and 183.sql create mode 100644 sql/SubqueriesHRDatabase/Write a subquery that returns a set of rows to find all departments that do actually have one or more employees assigned to them.sql create mode 100644 sql/SubqueriesHRDatabase/to display the department number, name ( first name and last name ), job and department name for all employees in the Finance department.sql create mode 100644 sql/Union/1. Write a query to display all salesmen and customer located in London.sql create mode 100644 sql/Union/2. Write a query to display distinct salesman and their cities.sql create mode 100644 sql/Union/3. Write a query to display all the salesmen and customer involved in this inventory management system.sql create mode 100644 sql/Union/4. Write a query to make a report of which salesman produce the largest and smallest orders on each date.sql create mode 100644 sql/Union/5. Write a query to make a report of which salesman produce the largest and smallest orders on each date and arranged the orders number in smallest to the largest number.sql create mode 100644 sql/Union/6. Write a query to list all the salesmen, and indicate those who do not have customers in their cities, as well as whose who do.sql create mode 100644 sql/Union/7. Write a query to that appends strings to the selected fields, indicating whether or not a specified salesman was matched to a customer in his city.sql create mode 100644 sql/Union/8. Write a query to create a union of two queries that shows the names, cities, and ratings of all customers. Those with a rating of 300 or greater.sql create mode 100644 sql/Union/9. Write a query that produces the name and number of each salesman and each customer with more than one current order. Put the results in alphabetical order.sql create mode 100644 sql/UserManagement/1. How to create a user on localhost.sql create mode 100644 sql/UserManagement/10. How to check permissions granted to a specific user.sql create mode 100644 sql/UserManagement/11. How to check the list of system privileges that the MySQL server supports.sql create mode 100644 sql/UserManagement/12. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour.sql create mode 100644 sql/UserManagement/13. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour.sql create mode 100644 sql/UserManagement/14. How to delete user.sql create mode 100644 sql/UserManagement/15. How to rename a user.sql create mode 100644 sql/UserManagement/16. How to create a user and granting no privileges.sql create mode 100644 sql/UserManagement/2. How to create a user for an IP address other than localhost.sql create mode 100644 sql/UserManagement/3. How to grant permission to a user to select only from localhost.sql create mode 100644 sql/UserManagement/4. How to grant a user permission to create, insert, update, delete and create temporary tables from localhost.sql create mode 100644 sql/UserManagement/5. How to grant a user permission to create, insert, update, delete and create temporary tables from any host.sql create mode 100644 sql/UserManagement/6. How to grant a user permission to select only from any host but to a specific table of a database.sql create mode 100644 sql/UserManagement/7. How to grant all privileges to a user from all machines.sql create mode 100644 sql/UserManagement/8. How to revoke all privileges from a user.sql create mode 100644 sql/UserManagement/9. How to revoke specific privilege from a user.sql create mode 100644 sql/View/1. Write a query to create a view for those salesmen belongs to the city New York.sql create mode 100644 sql/View/10. Write a query to create a view that shows the number of the salesman in each city.sql create mode 100644 sql/View/11. Write a query to create a view that shows the average and total orders for each salesman after his or her name. (Assume all names are unique).sql create mode 100644 sql/View/11. Write a query to create a view that shows the average and total orders for each salesman after his or her name.sql create mode 100644 sql/View/12. Write a query to create a view that shows each salesman with more than one customers.sql create mode 100644 sql/View/13. Write a query to create a view that shows all matches of customers with salesman.sql create mode 100644 sql/View/14. Write a query to create a view that shows the number of orders in each day.sql create mode 100644 sql/View/15. Write a query to create a view that finds the salesmen who issued orders on October 10th, 2012.sql create mode 100644 sql/View/16. Write a query to create a view that find the salesmen who issued orders on either August 17th, 2012 or October 10th, 2012.sql create mode 100644 sql/View/2. Write a query to create a view for all salesmen with columns salesman_id, name and city.sql create mode 100644 sql/View/3. Write a query to find the salesmen of the city New York who achieved the commission more than 13%.sql create mode 100644 sql/View/4.Write a query to create a view to getting a count of how many customers we have at each level of a grade.sql create mode 100644 sql/View/5. Write a query to create a view to keeping track the number of customers ordering, number of salesmen attached.sql create mode 100644 sql/View/6. Write a query to create a view that shows for each order the salesman and customer by name.sql create mode 100644 sql/View/7. Write a query to create a view that finds the salesman who has the customer with the highest order of a day.sql create mode 100644 sql/View/8. Write a query to create a view that finds the salesman who has the customer with the highest order at least 3 times on a day.sql create mode 100644 sql/View/9. Write a query to create a view that shows all of the customers who have the highest grade.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find all those customers with all information whose names are ending with the letter 'n'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find that customer with all information who does not get any grade except NULL.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find that customer with all information who gets a grade except NULL value.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find that customers whose name begin with the letter 'B'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the character ( % ) in its column 'col1'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the escape character in its column 'col1'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the escape character underscore ( _ ) in its column 'col1'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the string in its column 'col1'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the character ( % ) in its column 'col1'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the character underscore ( _ ) in its column 'col1'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the escape character in its column 'col1'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the string in its column 'col1'..sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the string in its column 'col1'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information who come from the city either Paris or Rome.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information who get the commission within a range of 0.12 and 0.14.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information whose name containing the 1st character is 'N' and the 4th character is 'l'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all other information and name started with any latter 'A' and 'L'.sql create mode 100644 sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all other information and name started with other than any latter within 'A' and 'L'.sql create mode 100644 sql/WildcardSpecialOperators/Write a query in SQL to display all the data of employees whose last name begins with an 'D'.sql create mode 100644 sql/WildcardSpecialOperators/Write a query to filter those salesmen with all information who comes from any of the cities Paris and Rome.sql create mode 100644 sql/WildcardSpecialOperators/Write a query to filter those salesmen with all information who likes to leave other cities than Paris and Rome.sql create mode 100644 sql/WildcardSpecialOperators/Write a query to sort out those customers with all information whose ID value is within any of 3007, 3008 and 3009.sql diff --git a/sql/AggregateFunctions/Write a SQL query to calculate the average price of all the products.sql b/sql/AggregateFunctions/Write a SQL query to calculate the average price of all the products.sql new file mode 100644 index 0000000..2faf7f9 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL query to calculate the average price of all the products.sql @@ -0,0 +1,3 @@ +/*Write a SQL query to calculate the average price of all the products.*/ +SELECT AVG(pro_price) AS "Average Price" + FROM item_mast; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL query to display the average price of each company's products, along with their code.sql b/sql/AggregateFunctions/Write a SQL query to display the average price of each company's products, along with their code.sql new file mode 100644 index 0000000..91a467e --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL query to display the average price of each company's products, along with their code.sql @@ -0,0 +1,5 @@ +/*Write a SQL query to display the average price of each company's products, along with their code.*/ +SELECT AVG(pro_price) AS "Average Price", + pro_com AS "Company ID" + FROM item_mast +OUP BY pro_com; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL query to find the number of products with a price more than or equal to Rs.350.sql b/sql/AggregateFunctions/Write a SQL query to find the number of products with a price more than or equal to Rs.350.sql new file mode 100644 index 0000000..0d86715 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL query to find the number of products with a price more than or equal to Rs.350.sql @@ -0,0 +1,4 @@ +/*Write a SQL query to find the number of products with a price more than or equal to Rs.350.*/ +SELECT COUNT(*) AS "Number of Products" + FROM item_mast + WHERE pro_price >= 350; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement find the number of customers who gets at least a gradation for hisor her performance..sql b/sql/AggregateFunctions/Write a SQL statement find the number of customers who gets at least a gradation for hisor her performance..sql new file mode 100644 index 0000000..7c35cd0 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement find the number of customers who gets at least a gradation for hisor her performance..sql @@ -0,0 +1,3 @@ +/*Write a SQL statement find the number of customers who gets at least a gradation for his/her performance.*/ + SELECT COUNT (ALL grade) + FROM customer; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement that counts all orders for a date August 17th, 2012.sql b/sql/AggregateFunctions/Write a SQL statement that counts all orders for a date August 17th, 2012.sql new file mode 100644 index 0000000..dfbc9d7 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement that counts all orders for a date August 17th, 2012.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement that counts all orders for a date August 17th, 2012.*/ +SELECT COUNT(*) +FROM orders +WHERE ord_date='2012-08-17'; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement that counts the number of different non NULL city values for salesmen.sql b/sql/AggregateFunctions/Write a SQL statement that counts the number of different non NULL city values for salesmen.sql new file mode 100644 index 0000000..7486261 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement that counts the number of different non NULL city values for salesmen.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement that counts the number of different non NULL city values for salesmen.*/ +SELECT COUNT(*) +FROM salesman +WHERE city IS NOT NULL; diff --git a/sql/AggregateFunctions/Write a SQL statement to display customer details (ID and purchase amount) whose and highest purchase amount is more than 1000..sql b/sql/AggregateFunctions/Write a SQL statement to display customer details (ID and purchase amount) whose and highest purchase amount is more than 1000..sql new file mode 100644 index 0000000..ad783fd --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to display customer details (ID and purchase amount) whose and highest purchase amount is more than 1000..sql @@ -0,0 +1,7 @@ +/*Write a SQL statement to display customer details (ID and purchase amount) whose IDs are within the range 3002 and 3007 +and highest purchase amount is more than 1000.*/ +SELECT customer_id,MAX(purch_amt) +FROM orders +WHERE customer_id BETWEEN 3002 and 3007 +GROUP BY customer_id +HAVING MAX(purch_amt)>1000; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the average purchase amount of all orders.sql b/sql/AggregateFunctions/Write a SQL statement to find the average purchase amount of all orders.sql new file mode 100644 index 0000000..572426c --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the average purchase amount of all orders.sql @@ -0,0 +1,3 @@ +/*Write a SQL statement to find the average purchase amount of all orders.*/ + SELECT AVG (purch_amt) + FROM orders; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount on a date '2012-08-17' for each salesman with their ID.sql b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount on a date '2012-08-17' for each salesman with their ID.sql new file mode 100644 index 0000000..25bd69c --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount on a date '2012-08-17' for each salesman with their ID.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find the highest purchase amount on a date '2012-08-17' for each salesman with their ID.*/ + SELECT salesman_id,MAX(purch_amt) + FROM orders + WHERE ord_date = '2012-08-17' + GROUP BY salesman_id; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount ordered by the each customer on a particular date with their ID, order date and highest purchase amount.sql b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount ordered by the each customer on a particular date with their ID, order date and highest purchase amount.sql new file mode 100644 index 0000000..effaeba --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount ordered by the each customer on a particular date with their ID, order date and highest purchase amount.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find the highest purchase amount ordered by the each customer on a particular +date with their ID, order date and highest purchase amount.*/ +SELECT customer_id,ord_date,MAX(purch_amt) +FROM orders +GROUP BY customer_id,ord_date; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount ordered by the each customer with their ID and highest purchase amount.sql b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount ordered by the each customer with their ID and highest purchase amount.sql new file mode 100644 index 0000000..d4060a8 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount ordered by the each customer with their ID and highest purchase amount.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find the highest purchase amount ordered by the each + customer with their ID and highest purchase amount. */ + SELECT customer_id,MAX(purch_amt) +FROM orders +GROUP BY customer_id; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID amount in a day is within the list 2000, 3000, 5760 and 6000..sql b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID amount in a day is within the list 2000, 3000, 5760 and 6000..sql new file mode 100644 index 0000000..02c2384 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID amount in a day is within the list 2000, 3000, 5760 and 6000..sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to find the highest purchase amount with their ID and order date, for only those customers + who have a higher purchase amount in a day is within the list 2000, 3000, 5760 and 6000.*/ + SELECT customer_id,ord_date,MAX(purch_amt) +FROM orders +GROUP BY customer_id,ord_date +HAVING MAX(purch_amt) IN(2000 ,3000,5760, 6000); \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID and order date, for only those customers who have highest purchase amount in a day is more than 2000.sql b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID and order date, for only those customers who have highest purchase amount in a day is more than 2000.sql new file mode 100644 index 0000000..9d99296 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID and order date, for only those customers who have highest purchase amount in a day is more than 2000.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to find the highest purchase amount with their ID and order date, for only those customers who have + highest purchase amount in a day is more than 2000.*/ + SELECT customer_id,ord_date,MAX(purch_amt) +FROM orders +GROUP BY customer_id,ord_date +HAVING MAX(purch_amt)>2000.00; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID and order date, for those customers who have a higher purchase.sql b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID and order date, for those customers who have a higher purchase.sql new file mode 100644 index 0000000..9424858 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID and order date, for those customers who have a higher purchase.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to find the highest purchase amount with their ID and order date, +for those customers who have a higher purchase amount in a day is within the range 2000 and 6000.*/ +SELECT customer_id,ord_date,MAX(purch_amt) +FROM orders +GROUP BY customer_id,ord_date +HAVING MAX(purch_amt) BETWEEN 2000 AND 6000; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID, for only those customers whose ID is within the range 3002 and 3007.sql b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID, for only those customers whose ID is within the range 3002 and 3007.sql new file mode 100644 index 0000000..3669cf3 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID, for only those customers whose ID is within the range 3002 and 3007.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to find the highest purchase amount with their ID, for only those customers whose ID is within +the range 3002 and 3007.*/ +SELECT customer_id,MAX(purch_amt) +FROM orders +WHERE customer_id BETWEEN 3002 and 3007 +GROUP BY customer_id; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID, for only those salesmen whose ID is within the range 5003 and 5008.sql b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID, for only those salesmen whose ID is within the range 5003 and 5008.sql new file mode 100644 index 0000000..ee1db75 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the highest purchase amount with their ID, for only those salesmen whose ID is within the range 5003 and 5008.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to find the highest purchase amount with their ID, for only those salesmen +whose ID is within the range 5003 and 5008.*/ +SELECT salesman_id,MAX(purch_amt) +FROM orders +GROUP BY salesman_id +HAVING salesman_id BETWEEN 5003 AND 5008; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the number of salesmen currently listing for all of their customers.sql b/sql/AggregateFunctions/Write a SQL statement to find the number of salesmen currently listing for all of their customers.sql new file mode 100644 index 0000000..fbacbd8 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the number of salesmen currently listing for all of their customers.sql @@ -0,0 +1,3 @@ +/*Write a SQL statement to find the number of salesmen currently listing for all of their customers.*/ +SELECT COUNT (DISTINCT salesman_id) +FROM orders; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to find the total purchase amount for all orders.sql b/sql/AggregateFunctions/Write a SQL statement to find the total purchase amount for all orders.sql new file mode 100644 index 0000000..99cdd1f --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to find the total purchase amount for all orders.sql @@ -0,0 +1,3 @@ +/*Write a SQL statement to find the total purchase amount for all orders.*/ + SELECT SUM (purch_amt) + FROM orders; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to know how many customers have listed their names.sql b/sql/AggregateFunctions/Write a SQL statement to know how many customers have listed their names.sql new file mode 100644 index 0000000..cd16dfe --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to know how many customers have listed their names.sql @@ -0,0 +1,3 @@ +/*Write a SQL statement to know how many customers have listed their names.*/ +SELECT COUNT(*) +FROM customer; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to know the maximum purchase amount of all the orders.sql b/sql/AggregateFunctions/Write a SQL statement to know the maximum purchase amount of all the orders.sql new file mode 100644 index 0000000..e85d241 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to know the maximum purchase amount of all the orders.sql @@ -0,0 +1,3 @@ +/*Write a SQL statement to know the maximum purchase amount of all the orders.*/ +SELECT MAX (purch_amt) +FROM orders; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement to know the minimum purchase amount of all the orders.sql b/sql/AggregateFunctions/Write a SQL statement to know the minimum purchase amount of all the orders.sql new file mode 100644 index 0000000..9395b20 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement to know the minimum purchase amount of all the orders.sql @@ -0,0 +1,3 @@ +/*Write a SQL statement to know the minimum purchase amount of all the orders. */ +SELECT MIN(purch_amt) +FROM orders; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a SQL statement which selects the highest grade for each of the cities of the customers.sql b/sql/AggregateFunctions/Write a SQL statement which selects the highest grade for each of the cities of the customers.sql new file mode 100644 index 0000000..4c54717 --- /dev/null +++ b/sql/AggregateFunctions/Write a SQL statement which selects the highest grade for each of the cities of the customers.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement which selects the highest grade for each of the cities of the customers.*/ +SELECT city,MAX(grade) +FROM customer +GROUP BY city; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a query in SQL to find the number of employees in each department along with the department code.sql b/sql/AggregateFunctions/Write a query in SQL to find the number of employees in each department along with the department code.sql new file mode 100644 index 0000000..9ba64e9 --- /dev/null +++ b/sql/AggregateFunctions/Write a query in SQL to find the number of employees in each department along with the department code.sql @@ -0,0 +1,4 @@ +/*Write a query in SQL to find the number of employees in each department along with the department code.*/ +SELECT emp_dept, COUNT(*) + FROM emp_details + GROUP BY emp_dept; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a query in SQL to find the sum of the allotment amount of all departments.sql b/sql/AggregateFunctions/Write a query in SQL to find the sum of the allotment amount of all departments.sql new file mode 100644 index 0000000..d0ef5f8 --- /dev/null +++ b/sql/AggregateFunctions/Write a query in SQL to find the sum of the allotment amount of all departments.sql @@ -0,0 +1,3 @@ +/*Write a query in SQL to find the sum of the allotment amount of all departments.*/ +SELECT SUM(dpt_allotment) +FROM emp_department; \ No newline at end of file diff --git a/sql/AggregateFunctions/Write a query that counts the number of salesmen with their order date and ID registering orders for each day.sql b/sql/AggregateFunctions/Write a query that counts the number of salesmen with their order date and ID registering orders for each day.sql new file mode 100644 index 0000000..d0b3dcd --- /dev/null +++ b/sql/AggregateFunctions/Write a query that counts the number of salesmen with their order date and ID registering orders for each day.sql @@ -0,0 +1,4 @@ +/*Write a query that counts the number of salesmen with their order date and ID registering orders for each day.*/ +SELECT ord_date,salesman_id,COUNT(*) +FROM orders +GROUP BY ord_date,salesman_id; \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Display all in reverse, where order dates equal to a specified date or customer id greater than a specified number and purchase amount less than a specified amount..sql b/sql/BooleanRelationalOperators/Display all in reverse, where order dates equal to a specified date or customer id greater than a specified number and purchase amount less than a specified amount..sql new file mode 100644 index 0000000..e69de29 diff --git a/sql/BooleanRelationalOperators/Display all in reverse, where order dates equal to a specified date or customer id greater than a specified number and purchase amount less than a specified amount.sql b/sql/BooleanRelationalOperators/Display all in reverse, where order dates equal to a specified date or customer id greater than a specified number and purchase amount less than a specified amount.sql new file mode 100644 index 0000000..bb44af4 --- /dev/null +++ b/sql/BooleanRelationalOperators/Display all in reverse, where order dates equal to a specified date or customer id greater than a specified number and purchase amount less than a specified amount.sql @@ -0,0 +1,7 @@ +/*Display all in reverse, where order dates equal to a specified date or +customer id greater than a specified number and purchase amount less than a specified amount. */ +SELECT * +FROM orders +WHERE NOT((ord_date ='2012-08-17' +OR customer_id>3005) +AND purch_amt<1000); \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a SQL query to display all orders where purchase amount less than a specified amount or order date and customer_id must not.sql b/sql/BooleanRelationalOperators/Write a SQL query to display all orders where purchase amount less than a specified amount or order date and customer_id must not.sql new file mode 100644 index 0000000..9b3e6eb --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a SQL query to display all orders where purchase amount less than a specified amount or order date and customer_id must not.sql @@ -0,0 +1,7 @@ +/*Write a SQL query to display all orders where purchase amount less than a specified amount or order date and customer_id must +not be greater than a specified data and less than a specified ID respectively.*/ +SELECT * +FROM orders +WHERE(purch_amt<200 OR +NOT(ord_date>='2012-02-10' +AND customer_id<3009)); \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a SQL query to display order number, purchase amount, achived, the unachieved percentage for those order which exceeds the 50% of the target value of 6000.sql b/sql/BooleanRelationalOperators/Write a SQL query to display order number, purchase amount, achived, the unachieved percentage for those order which exceeds the 50% of the target value of 6000.sql new file mode 100644 index 0000000..10d0be6 --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a SQL query to display order number, purchase amount, achived, the unachieved percentage for those order which exceeds the 50% of the target value of 6000.sql @@ -0,0 +1,7 @@ +/*Write a SQL query to display order number, purchase amount, achived, the unachieved percentage for those order +which exceeds the 50% of the target value of 6000. */ +SELECT ord_no,purch_amt, +(100*purch_amt)/6000 AS "Achieved %", +(100*(6000-purch_amt)/6000) AS "Unachieved %" +FROM orders +WHERE (100*purch_amt)/6000>50; \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a SQL query to display those customers who are neither belongs to the city New York nor grade value is more than 100.sql b/sql/BooleanRelationalOperators/Write a SQL query to display those customers who are neither belongs to the city New York nor grade value is more than 100.sql new file mode 100644 index 0000000..3246470 --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a SQL query to display those customers who are neither belongs to the city New York nor grade value is more than 100.sql @@ -0,0 +1,4 @@ +/*Write a SQL query to display those customers who are neither belongs to the city New York nor grade value is more than 100. */ +SELECT * +FROM customer +WHERE NOT (city = 'New York' OR grade>100); \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a SQL statement to display all customers, who are either belongs to the city New York or had a grade above 100.sql b/sql/BooleanRelationalOperators/Write a SQL statement to display all customers, who are either belongs to the city New York or had a grade above 100.sql new file mode 100644 index 0000000..91e183d --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a SQL statement to display all customers, who are either belongs to the city New York or had a grade above 100.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to display all customers, who are either belongs to the city New York or had a grade above 100. */ +SELECT * +FROM customer +WHERE city = 'New York' OR grade>100; \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a SQL statement to display all the customers, who are either belongs to the city New York or not had a grade above 100.sql b/sql/BooleanRelationalOperators/Write a SQL statement to display all the customers, who are either belongs to the city New York or not had a grade above 100.sql new file mode 100644 index 0000000..8891561 --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a SQL statement to display all the customers, who are either belongs to the city New York or not had a grade above 100.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to display all the customers, who are either belongs to the city New York or +not had a grade above 100. */ +SELECT * +FROM customer +WHERE city = 'New York' OR NOT grade>100; \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a SQL statement to display either those orders which are not issued on date 2012-09-10 and issued by the salesman whose ID is 505 and below or t.sql b/sql/BooleanRelationalOperators/Write a SQL statement to display either those orders which are not issued on date 2012-09-10 and issued by the salesman whose ID is 505 and below or t.sql new file mode 100644 index 0000000..515da60 --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a SQL statement to display either those orders which are not issued on date 2012-09-10 and issued by the salesman whose ID is 505 and below or t.sql @@ -0,0 +1,7 @@ +/*Write a SQL statement to display either those orders which are not issued on date 2012-09-10 and issued by the + salesman whose ID is 505 and below or those orders which purchase amount is 1000.00 and below.*/ + SELECT * + FROM orders + WHERE NOT ((ord_date ='2012-09-10' + AND salesman_id>505) + OR purch_amt>1000.00); \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a SQL statement to display salesman_id, name, city and commission who gets the commission within the range more than 0.10% and less than 0.12%.sql b/sql/BooleanRelationalOperators/Write a SQL statement to display salesman_id, name, city and commission who gets the commission within the range more than 0.10% and less than 0.12%.sql new file mode 100644 index 0000000..83aa207 --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a SQL statement to display salesman_id, name, city and commission who gets the commission within the range more than 0.10% and less than 0.12%.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to display salesman_id, name, city and commission who gets the +commission within the range more than 0.10% and less than 0.12%.*/ + SELECT salesman_id,name,city,commission + FROM salesman + WHERE (commission > 0.10 + AND commission< 0.12); \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a query in SQL to display all the data of employees that work in department 47 or department 63.sql b/sql/BooleanRelationalOperators/Write a query in SQL to display all the data of employees that work in department 47 or department 63.sql new file mode 100644 index 0000000..c6153d2 --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a query in SQL to display all the data of employees that work in department 47 or department 63.sql @@ -0,0 +1,4 @@ +/*Write a query in SQL to display all the data of employees that work in department 47 or department 63.*/ + SELECT * + FROM emp_details + WHERE emp_dept = 47 OR emp_dept = 63; \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a query in SQL to find the data of employees whose last name is Dosni or Mardy.sql b/sql/BooleanRelationalOperators/Write a query in SQL to find the data of employees whose last name is Dosni or Mardy.sql new file mode 100644 index 0000000..0a5abc9 --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a query in SQL to find the data of employees whose last name is Dosni or Mardy.sql @@ -0,0 +1,4 @@ +/*Write a query in SQL to find the data of employees whose last name is Dosni or Mardy.*/ +SELECT * + FROM emp_details + WHERE emp_lname ='Dosni' OR emp_lname= 'Mardy'; \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a query statement to display all customers in New York who have a grade value above 100.sql b/sql/BooleanRelationalOperators/Write a query statement to display all customers in New York who have a grade value above 100.sql new file mode 100644 index 0000000..f3ad90b --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a query statement to display all customers in New York who have a grade value above 100.sql @@ -0,0 +1,4 @@ +/*Write a query statement to display all customers in New York who have a grade value above 100.*/ +SELECT * +FROM customer +WHERE city = 'New York' AND grade>100; \ No newline at end of file diff --git a/sql/BooleanRelationalOperators/Write a query to display all customers with a grade above 100.sql b/sql/BooleanRelationalOperators/Write a query to display all customers with a grade above 100.sql new file mode 100644 index 0000000..7062183 --- /dev/null +++ b/sql/BooleanRelationalOperators/Write a query to display all customers with a grade above 100.sql @@ -0,0 +1,4 @@ +/*Write a query to display all customers with a grade above 100.*/ +SELECT * +FROM customer +WHERE grade > 100; \ No newline at end of file diff --git a/sql/FormattingOutput/Write a SQL statement to arrange the orders according to the order_date in such a manner that.sql b/sql/FormattingOutput/Write a SQL statement to arrange the orders according to the order_date in such a manner that.sql new file mode 100644 index 0000000..73b70d4 --- /dev/null +++ b/sql/FormattingOutput/Write a SQL statement to arrange the orders according to the order_date in such a manner that.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to arrange the orders according to the order_date in such a manner that +the latest date will come first then previous dates.*/ +SELECT * +FROM orders +ORDER BY ord_date DESC; \ No newline at end of file diff --git a/sql/FormattingOutput/Write a SQL statement to display customer name, city and grade in such a manner that, the customer holding highest grade will come first.sql b/sql/FormattingOutput/Write a SQL statement to display customer name, city and grade in such a manner that, the customer holding highest grade will come first.sql new file mode 100644 index 0000000..487271c --- /dev/null +++ b/sql/FormattingOutput/Write a SQL statement to display customer name, city and grade in such a manner that, the customer holding highest grade will come first.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to display customer name, city and grade in such a manner that, +the customer holding highest grade will come first.*/ +SELECT cust_name,city,grade +FROM customer +ORDER BY 3 DESC; \ No newline at end of file diff --git a/sql/FormattingOutput/Write a SQL statement to display the commission with the percent sign ( % ) with salesman ID, name and city columns for all the salesmen.sql b/sql/FormattingOutput/Write a SQL statement to display the commission with the percent sign ( % ) with salesman ID, name and city columns for all the salesmen.sql new file mode 100644 index 0000000..925a4ce --- /dev/null +++ b/sql/FormattingOutput/Write a SQL statement to display the commission with the percent sign ( % ) with salesman ID, name and city columns for all the salesmen.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to display the commission with the percent sign ( % ) with salesman ID, + name and city columns for all the salesmen.*/ + SELECT salesman_id,name,city,'%',commission*100 +FROM salesman; \ No newline at end of file diff --git a/sql/FormattingOutput/Write a SQL statement to display the customer name, city, and grade, etc. and the display will be arranged according to the smallest customer ID.sql b/sql/FormattingOutput/Write a SQL statement to display the customer name, city, and grade, etc. and the display will be arranged according to the smallest customer ID.sql new file mode 100644 index 0000000..07cd31f --- /dev/null +++ b/sql/FormattingOutput/Write a SQL statement to display the customer name, city, and grade, etc. and the display will be arranged according to the smallest customer ID.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to display the customer name, city, and grade, etc. and the display will +be arranged according to the smallest customer ID.*/ +SELECT cust_name,city,grade +FROM customer +ORDER BY customer_id; \ No newline at end of file diff --git a/sql/FormattingOutput/Write a SQL statement to display the orders with all information in such a manner that, the older order date will come first and the highest purchase amount of same day will come first.sql b/sql/FormattingOutput/Write a SQL statement to display the orders with all information in such a manner that, the older order date will come first and the highest purchase amount of same day will come first.sql new file mode 100644 index 0000000..42aac2f --- /dev/null +++ b/sql/FormattingOutput/Write a SQL statement to display the orders with all information in such a manner that, the older order date will come first and the highest purchase amount of same day will come first.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to display the orders with all information in such a manner that, the older order + date will come first and the highest purchase amount of same day will come first.*/ + SELECT * +FROM orders +ORDER BY ord_date,purch_amt DESC; \ No newline at end of file diff --git a/sql/FormattingOutput/Write a SQL statement to find out the number of orders booked for each day and display it in such a format like.sql b/sql/FormattingOutput/Write a SQL statement to find out the number of orders booked for each day and display it in such a format like.sql new file mode 100644 index 0000000..d9780ec --- /dev/null +++ b/sql/FormattingOutput/Write a SQL statement to find out the number of orders booked for each day and display it in such a format like.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to find out the number of orders booked for each day and display it in + such a format like "For 2001-10-10 there are 15 orders".*/ + SELECT ' For',ord_date,',there are', +COUNT (DISTINCT ord_no),'orders.' +FROM orders +GROUP BY ord_date; \ No newline at end of file diff --git a/sql/FormattingOutput/Write a SQL statement to make a report with customer ID in such a manner that, the largest number of orders booked by the customer will come first.sql b/sql/FormattingOutput/Write a SQL statement to make a report with customer ID in such a manner that, the largest number of orders booked by the customer will come first.sql new file mode 100644 index 0000000..8bc982e --- /dev/null +++ b/sql/FormattingOutput/Write a SQL statement to make a report with customer ID in such a manner that, the largest number of orders booked by the customer will come first.sql @@ -0,0 +1,7 @@ +/*Write a SQL statement to make a report with customer ID in such a manner that, the largest number of orders booked by the +customer will come first along with their highest purchase amount.*/ + SELECT customer_id, COUNT(DISTINCT ord_no), + MAX(purch_amt) + FROM orders + GROUP BY customer_id + ORDER BY 2 DESC; \ No newline at end of file diff --git a/sql/FormattingOutput/Write a query to display the orders according to the order number arranged by ascending order.sql b/sql/FormattingOutput/Write a query to display the orders according to the order number arranged by ascending order.sql new file mode 100644 index 0000000..126840e --- /dev/null +++ b/sql/FormattingOutput/Write a query to display the orders according to the order number arranged by ascending order.sql @@ -0,0 +1,4 @@ +/*Write a query to display the orders according to the order number arranged by ascending order.*/ +SELECT * +FROM orders +ORDER BY ord_no; \ No newline at end of file diff --git a/sql/JoinHRDatabase/1. Write a query in SQL to display the first name, last name, department number, and department name for each employee.sql b/sql/JoinHRDatabase/1. Write a query in SQL to display the first name, last name, department number, and department name for each employee.sql new file mode 100644 index 0000000..702db87 --- /dev/null +++ b/sql/JoinHRDatabase/1. Write a query in SQL to display the first name, last name, department number, and department name for each employee.sql @@ -0,0 +1,6 @@ +/*1. Write a query in SQL to display the first name, last name, department number, and department name for each employee. */ +SELECT E.first_name , E.last_name , + E.department_id , D.department_name + FROM employees E + JOIN departments D + ON E.department_id = D.department_id; \ No newline at end of file diff --git a/sql/JoinHRDatabase/10. Write a query in SQL to display the first name, last name, department number and name, for all employees who have or have not any department.sql b/sql/JoinHRDatabase/10. Write a query in SQL to display the first name, last name, department number and name, for all employees who have or have not any department.sql new file mode 100644 index 0000000..a238260 --- /dev/null +++ b/sql/JoinHRDatabase/10. Write a query in SQL to display the first name, last name, department number and name, for all employees who have or have not any department.sql @@ -0,0 +1,6 @@ +/*10. Write a query in SQL to display the first name, last name, department number and name, for all employees who have or have + not any department.*/ +SELECT E.first_name, E.last_name, E.department_id, D.department_name + FROM employees E + LEFT OUTER JOIN departments D + ON E.department_id = D.department_id; \ No newline at end of file diff --git a/sql/JoinHRDatabase/11. Write a query in SQL to display the first name of all employees and the first name of their manager including those who does not working under any manager.sql b/sql/JoinHRDatabase/11. Write a query in SQL to display the first name of all employees and the first name of their manager including those who does not working under any manager.sql new file mode 100644 index 0000000..baa1ab0 --- /dev/null +++ b/sql/JoinHRDatabase/11. Write a query in SQL to display the first name of all employees and the first name of their manager including those who does not working under any manager.sql @@ -0,0 +1,7 @@ +/*11. Write a query in SQL to display the first name of all employees and the first name of their manager including those who + does not working under any manager.*/ +SELECT E.first_name AS "Employee Name", + M.first_name AS "Manager" + FROM employees E + LEFT OUTER JOIN employees M + ON E.manager_id = M.employee_id; \ No newline at end of file diff --git a/sql/JoinHRDatabase/13. Write a query in SQL to display the job title, department name, full name (first and last name ) of employee, and starting date for all the jobs.sql b/sql/JoinHRDatabase/13. Write a query in SQL to display the job title, department name, full name (first and last name ) of employee, and starting date for all the jobs.sql new file mode 100644 index 0000000..e9b3fc2 --- /dev/null +++ b/sql/JoinHRDatabase/13. Write a query in SQL to display the job title, department name, full name (first and last name ) of employee, and starting date for all the jobs.sql @@ -0,0 +1,8 @@ +/*13. Write a query in SQL to display the job title, department name, full name (first and last name ) of employee, and + starting date for all the jobs which started on or after 1st January, 1993 and ending with on or before 31 August, 1997.*/ +SELECT job_title, department_name, first_name || ' ' || last_name AS Employee_name, start_date + FROM job_history + JOIN jobs USING (job_id) + JOIN departments USING (department_id) + JOIN employees USING (employee_id) + WHERE start_date>='1993-01-01' AND start_date<='1997-08-31'; \ No newline at end of file diff --git a/sql/JoinHRDatabase/14. Write a query in SQL to display job title, full name (first and last name ) of employee, and the difference between maximum salary for the job and salary of the employee.sql b/sql/JoinHRDatabase/14. Write a query in SQL to display job title, full name (first and last name ) of employee, and the difference between maximum salary for the job and salary of the employee.sql new file mode 100644 index 0000000..89a64d2 --- /dev/null +++ b/sql/JoinHRDatabase/14. Write a query in SQL to display job title, full name (first and last name ) of employee, and the difference between maximum salary for the job and salary of the employee.sql @@ -0,0 +1,6 @@ +/*14. Write a query in SQL to display job title, full name (first and last name ) of employee, and the difference between + maximum salary for the job and salary of the employee.*/ +SELECT job_title, first_name || ' ' || last_name AS Employee_name, + max_salary-salary AS salary_difference + FROM employees + NATURAL JOIN jobs; \ No newline at end of file diff --git a/sql/JoinHRDatabase/15. Write a query in SQL to display the name of the department, average salary and number of employees working in that department who got commission.sql b/sql/JoinHRDatabase/15. Write a query in SQL to display the name of the department, average salary and number of employees working in that department who got commission.sql new file mode 100644 index 0000000..50ccc27 --- /dev/null +++ b/sql/JoinHRDatabase/15. Write a query in SQL to display the name of the department, average salary and number of employees working in that department who got commission.sql @@ -0,0 +1,6 @@ +/*15. Write a query in SQL to display the name of the department, average salary and number of employees working in that + department who got commission.*/ +SELECT department_name, AVG(salary), COUNT(commission_pct) + FROM departments + JOIN employees USING (department_id) +GROUP BY department_name; \ No newline at end of file diff --git a/sql/JoinHRDatabase/17. Write a query in SQL to display the name of the country, city, and the departments which are running there.sql b/sql/JoinHRDatabase/17. Write a query in SQL to display the name of the country, city, and the departments which are running there.sql new file mode 100644 index 0000000..d50d7a7 --- /dev/null +++ b/sql/JoinHRDatabase/17. Write a query in SQL to display the name of the country, city, and the departments which are running there.sql @@ -0,0 +1,5 @@ +/*17. Write a query in SQL to display the name of the country, city, and the departments which are running there.*/ +SELECT country_name,city, department_name + FROM countries + JOIN locations USING (country_id) + JOIN departments USING (location_id); \ No newline at end of file diff --git a/sql/JoinHRDatabase/18. Write a query in SQL to display department name and the full name (first and last name) of the manager.sql b/sql/JoinHRDatabase/18. Write a query in SQL to display department name and the full name (first and last name) of the manager.sql new file mode 100644 index 0000000..687cca1 --- /dev/null +++ b/sql/JoinHRDatabase/18. Write a query in SQL to display department name and the full name (first and last name) of the manager.sql @@ -0,0 +1,5 @@ +/*18. Write a query in SQL to display department name and the full name (first and last name) of the manager.*/ +SELECT department_name, first_name || ' ' || last_name AS name_of_manager + FROM departments D + JOIN employees E + ON (D.manager_id=E.employee_id); \ No newline at end of file diff --git a/sql/JoinHRDatabase/19. Write a query in SQL to display job title and average salary of employees.sql b/sql/JoinHRDatabase/19. Write a query in SQL to display job title and average salary of employees.sql new file mode 100644 index 0000000..7a4d38d --- /dev/null +++ b/sql/JoinHRDatabase/19. Write a query in SQL to display job title and average salary of employees.sql @@ -0,0 +1,5 @@ +/*19. Write a query in SQL to display job title and average salary of employees.*/ +SELECT job_title, AVG(salary) + FROM employees + NATURAL JOIN jobs + GROUP BY job_title; \ No newline at end of file diff --git a/sql/JoinHRDatabase/2. Write a query in SQL to display the first and last name, department, city, and state province for each employee.sql b/sql/JoinHRDatabase/2. Write a query in SQL to display the first and last name, department, city, and state province for each employee.sql new file mode 100644 index 0000000..df4dbf2 --- /dev/null +++ b/sql/JoinHRDatabase/2. Write a query in SQL to display the first and last name, department, city, and state province for each employee.sql @@ -0,0 +1,8 @@ +/*2. Write a query in SQL to display the first and last name, department, city, and state province for each employee. */ +SELECT E.first_name,E.last_name, + D.department_name, L.city, L.state_province + FROM employees E + JOIN departments D + ON E.department_id = D.department_id + JOIN locations L + ON D.location_id = L.location_id; \ No newline at end of file diff --git a/sql/JoinHRDatabase/20. Write a query in SQL to display the details of jobs which was done by any of the employees who is presently earning a salary on and above 12000.sql b/sql/JoinHRDatabase/20. Write a query in SQL to display the details of jobs which was done by any of the employees who is presently earning a salary on and above 12000.sql new file mode 100644 index 0000000..d7f9b6c --- /dev/null +++ b/sql/JoinHRDatabase/20. Write a query in SQL to display the details of jobs which was done by any of the employees who is presently earning a salary on and above 12000.sql @@ -0,0 +1,7 @@ +/*20. Write a query in SQL to display the details of jobs which was done by any of the employees who is presently earning a + salary on and above 12000.*/ +SELECT a.* + FROM job_history a + JOIN employees m + ON (a.employee_id = m.employee_id) +WHERE salary >= 12000; \ No newline at end of file diff --git a/sql/JoinHRDatabase/21. Write a query in SQL to display the country name, city, and number of those departments where at leaste 2 employees are working.sql b/sql/JoinHRDatabase/21. Write a query in SQL to display the country name, city, and number of those departments where at leaste 2 employees are working.sql new file mode 100644 index 0000000..b246bfd --- /dev/null +++ b/sql/JoinHRDatabase/21. Write a query in SQL to display the country name, city, and number of those departments where at leaste 2 employees are working.sql @@ -0,0 +1,12 @@ +/*21. Write a query in SQL to display the country name, city, and number of those departments where at leaste 2 employees + are working.*/ +SELECT country_name,city, COUNT(department_id) + FROM countries + JOIN locations USING (country_id) + JOIN departments USING (location_id) +WHERE department_id IN + (SELECT department_id + FROM employees + GROUP BY department_id + HAVING COUNT(department_id)>=2) +GROUP BY country_name,city; \ No newline at end of file diff --git a/sql/JoinHRDatabase/22. Write a query in SQL to display the department name, full name (first and last name) of manager, and their city.sql b/sql/JoinHRDatabase/22. Write a query in SQL to display the department name, full name (first and last name) of manager, and their city.sql new file mode 100644 index 0000000..eca2586 --- /dev/null +++ b/sql/JoinHRDatabase/22. Write a query in SQL to display the department name, full name (first and last name) of manager, and their city.sql @@ -0,0 +1,6 @@ +/*22. Write a query in SQL to display the department name, full name (first and last name) of manager, and their city.*/ +SELECT department_name, first_name || ' ' || last_name AS name_of_manager, city + FROM departments D + JOIN employees E + ON (D.manager_id=E.employee_id) + JOIN locations L USING (location_id); \ No newline at end of file diff --git a/sql/JoinHRDatabase/23. Write a query in SQL to display the employee ID, job name, number of days worked in for all those jobs in department 80.sql b/sql/JoinHRDatabase/23. Write a query in SQL to display the employee ID, job name, number of days worked in for all those jobs in department 80.sql new file mode 100644 index 0000000..8e83ed1 --- /dev/null +++ b/sql/JoinHRDatabase/23. Write a query in SQL to display the employee ID, job name, number of days worked in for all those jobs in department 80.sql @@ -0,0 +1,5 @@ +/*23. Write a query in SQL to display the employee ID, job name, number of days worked in for all those jobs in department 80.*/ +SELECT employee_id, job_title, end_date-start_date DAYS + FROM job_history + NATURAL JOIN jobs + WHERE department_id=80; \ No newline at end of file diff --git a/sql/JoinHRDatabase/24. Write a query in SQL to display the full name (first and last name), and salary of those employees who working in any department located in London.sql b/sql/JoinHRDatabase/24. Write a query in SQL to display the full name (first and last name), and salary of those employees who working in any department located in London.sql new file mode 100644 index 0000000..99247b0 --- /dev/null +++ b/sql/JoinHRDatabase/24. Write a query in SQL to display the full name (first and last name), and salary of those employees who working in any department located in London.sql @@ -0,0 +1,7 @@ +/*24. Write a query in SQL to display the full name (first and last name), and salary of those employees who working in any + department located in London.*/ +SELECT first_name || ' ' || last_name AS Employee_name, salary + FROM employees + JOIN departments USING (department_id) + JOIN locations USING (location_id) + WHERE city = 'London'; \ No newline at end of file diff --git a/sql/JoinHRDatabase/25. Write a query in SQL to display full name(first and last name), job title, starting and ending date of last jobs for those employees with worked without a commission percentage.sql b/sql/JoinHRDatabase/25. Write a query in SQL to display full name(first and last name), job title, starting and ending date of last jobs for those employees with worked without a commission percentage.sql new file mode 100644 index 0000000..99fbe19 --- /dev/null +++ b/sql/JoinHRDatabase/25. Write a query in SQL to display full name(first and last name), job title, starting and ending date of last jobs for those employees with worked without a commission percentage.sql @@ -0,0 +1,9 @@ +/*25. Write a query in SQL to display full name(first and last name), job title, starting and ending date of last jobs for +those employees with worked without a commission percentage.*/ +SELECT first_name || ' ' || last_name AS Employee_name, + job_title, start_date, end_date + FROM job_history a + JOIN jobs b USING (job_id) + JOIN employees c + ON ( a.employee_id = c.employee_id) +WHERE commission_pct IS NULL; \ No newline at end of file diff --git a/sql/JoinHRDatabase/26. Write a query in SQL to display the department name and number of employees in each of the department.sql b/sql/JoinHRDatabase/26. Write a query in SQL to display the department name and number of employees in each of the department.sql new file mode 100644 index 0000000..669f14c --- /dev/null +++ b/sql/JoinHRDatabase/26. Write a query in SQL to display the department name and number of employees in each of the department.sql @@ -0,0 +1,5 @@ +/*26. Write a query in SQL to display the department name and number of employees in each of the department.*/ +SELECT department_name, COUNT(*) + FROM employees + NATURAL JOIN departments + GROUP BY department_name; \ No newline at end of file diff --git a/sql/JoinHRDatabase/3. Write a query in SQL to display the first name, last name, salary, and job grade for all employees.sql b/sql/JoinHRDatabase/3. Write a query in SQL to display the first name, last name, salary, and job grade for all employees.sql new file mode 100644 index 0000000..1c508e9 --- /dev/null +++ b/sql/JoinHRDatabase/3. Write a query in SQL to display the first name, last name, salary, and job grade for all employees.sql @@ -0,0 +1,5 @@ +/*3. Write a query in SQL to display the first name, last name, salary, and job grade for all employees. */ +SELECT E.first_name, E.last_name, E.salary, J.grade_level + FROM employees E + JOIN job_grades J + ON E.salary BETWEEN J.lowest_sal AND J.highest_sal; \ No newline at end of file diff --git a/sql/JoinHRDatabase/4. Write a query in SQL to display the first name, last name, department number and department name, for all employees for departments 80 or 40.sql b/sql/JoinHRDatabase/4. Write a query in SQL to display the first name, last name, department number and department name, for all employees for departments 80 or 40.sql new file mode 100644 index 0000000..e66393d --- /dev/null +++ b/sql/JoinHRDatabase/4. Write a query in SQL to display the first name, last name, department number and department name, for all employees for departments 80 or 40.sql @@ -0,0 +1,9 @@ +/*4. Write a query in SQL to display the first name, last name, department number and department name, for all employees for + departments 80 or 40. */ +SELECT E.first_name , E.last_name , + E.department_id , D.department_name + FROM employees E + JOIN departments D + ON E.department_id = D.department_id + AND E.department_id IN (80 , 40) + ORDER BY E.last_name; \ No newline at end of file diff --git a/sql/JoinHRDatabase/5. Write a query in SQL to display those employees who contain a letter z to their first name and also display their last name, department, city, and state province.sql b/sql/JoinHRDatabase/5. Write a query in SQL to display those employees who contain a letter z to their first name and also display their last name, department, city, and state province.sql new file mode 100644 index 0000000..b02712b --- /dev/null +++ b/sql/JoinHRDatabase/5. Write a query in SQL to display those employees who contain a letter z to their first name and also display their last name, department, city, and state province.sql @@ -0,0 +1,10 @@ +/*5. Write a query in SQL to display those employees who contain a letter z to their first name and also display their last name, +department, city, and state province.*/ +SELECT E.first_name,E.last_name, + D.department_name, L.city, L.state_province + FROM employees E + JOIN departments D + ON E.department_id = D.department_id + JOIN locations L + ON D.location_id = L.location_id + WHERE E.first_name LIKE '%z%'; \ No newline at end of file diff --git a/sql/JoinHRDatabase/6. Write a query in SQL to display all departments including those where does not have any employee.sql b/sql/JoinHRDatabase/6. Write a query in SQL to display all departments including those where does not have any employee.sql new file mode 100644 index 0000000..9331fd7 --- /dev/null +++ b/sql/JoinHRDatabase/6. Write a query in SQL to display all departments including those where does not have any employee.sql @@ -0,0 +1,5 @@ +/*6. Write a query in SQL to display all departments including those where does not have any employee.*/ +SELECT E.first_name, E.last_name, E.department_id, D.department_name + FROM employees E + RIGHT OUTER JOIN departments D + ON E.department_id = D.department_id; \ No newline at end of file diff --git a/sql/JoinHRDatabase/7. Write a query in SQL to display the first and last name and salary for those employees who earn less than the employee earn whose number is 182.sql b/sql/JoinHRDatabase/7. Write a query in SQL to display the first and last name and salary for those employees who earn less than the employee earn whose number is 182.sql new file mode 100644 index 0000000..462854d --- /dev/null +++ b/sql/JoinHRDatabase/7. Write a query in SQL to display the first and last name and salary for those employees who earn less than the employee earn whose number is 182.sql @@ -0,0 +1,7 @@ +/*7. Write a query in SQL to display the first and last name and salary for those employees who earn less than the employee +earn whose number is 182.*/ +SELECT E.first_name, E.last_name, E.salary + FROM employees E + JOIN employees S + ON E.salary < S.salary + AND S.employee_id = 182; \ No newline at end of file diff --git a/sql/JoinHRDatabase/8. Write a query in SQL to display the first name of all employees including the first name of their manager.sql b/sql/JoinHRDatabase/8. Write a query in SQL to display the first name of all employees including the first name of their manager.sql new file mode 100644 index 0000000..2046705 --- /dev/null +++ b/sql/JoinHRDatabase/8. Write a query in SQL to display the first name of all employees including the first name of their manager.sql @@ -0,0 +1,6 @@ +/*8. Write a query in SQL to display the first name of all employees including the first name of their manager.*/ +SELECT E.first_name AS "Employee Name", + M.first_name AS "Manager" + FROM employees E + JOIN employees M + ON E.manager_id = M.employee_id; \ No newline at end of file diff --git a/sql/JoinHRDatabase/9. Write a query in SQL to display the department name, city, and state province for each department.sql b/sql/JoinHRDatabase/9. Write a query in SQL to display the department name, city, and state province for each department.sql new file mode 100644 index 0000000..3c43ede --- /dev/null +++ b/sql/JoinHRDatabase/9. Write a query in SQL to display the department name, city, and state province for each department.sql @@ -0,0 +1,5 @@ +/*9. Write a query in SQL to display the department name, city, and state province for each department.*/ +SELECT D.department_name , L.city , L.state_province + FROM departments D + JOIN locations L + ON D.location_id = L.location_id; \ No newline at end of file diff --git a/sql/Joins/2Write a SQL query to display the average price of items of each company, showing the name of the company.sql b/sql/Joins/2Write a SQL query to display the average price of items of each company, showing the name of the company.sql new file mode 100644 index 0000000..9c7a33b --- /dev/null +++ b/sql/Joins/2Write a SQL query to display the average price of items of each company, showing the name of the company.sql @@ -0,0 +1,6 @@ +/*2Write a SQL query to display the average price of items of each company, showing the name of the company.*/ +SELECT AVG(pro_price), company_mast.com_name + FROM item_mast INNER JOIN company_mast + ON item_mast.pro_com= company_mast.com_id + GROUP BY company_mast.com_name + HAVING AVG(pro_price) >= 350; \ No newline at end of file diff --git a/sql/Joins/3Write a SQL query to display the average price of items of each company, showing the name of the company.sql b/sql/Joins/3Write a SQL query to display the average price of items of each company, showing the name of the company.sql new file mode 100644 index 0000000..b15ac0e --- /dev/null +++ b/sql/Joins/3Write a SQL query to display the average price of items of each company, showing the name of the company.sql @@ -0,0 +1,10 @@ +/*3Write a SQL query to display the average price of items of each company, showing the name of the company.*/ + SELECT A.pro_name, A.pro_price, F.com_name + FROM item_mast A INNER JOIN company_mast F + ON A.pro_com = F.com_id + AND A.pro_price = + ( + SELECT MAX(A.pro_price) + FROM item_mast A + WHERE A.pro_com = F.com_id + ); \ No newline at end of file diff --git a/sql/Joins/Write a SQL query to display all the data from the item_mast, including all the data for each item's producer company.sql b/sql/Joins/Write a SQL query to display all the data from the item_mast, including all the data for each item's producer company.sql new file mode 100644 index 0000000..f1f137f --- /dev/null +++ b/sql/Joins/Write a SQL query to display all the data from the item_mast, including all the data for each item's producer company.sql @@ -0,0 +1,5 @@ +/*Write a SQL query to display all the data from the item_mast, including all the data for each item's producer company.*/ +SELECT * + FROM item_mast + INNER JOIN company_mast + ON item_mast.pro_com= company_mast.com_id; \ No newline at end of file diff --git a/sql/Joins/Write a SQL query to display the average price of items of each company, showing the name of the company.sql b/sql/Joins/Write a SQL query to display the average price of items of each company, showing the name of the company.sql new file mode 100644 index 0000000..a7fc71a --- /dev/null +++ b/sql/Joins/Write a SQL query to display the average price of items of each company, showing the name of the company.sql @@ -0,0 +1,6 @@ +/*Write a SQL query to display the average price of items of each company, showing the name of the company.*/ +SELECT AVG(pro_price), company_mast.com_name + FROM item_mast INNER + JOIN company_mast + ON item_mast.pro_com= company_mast.com_id + GROUP BY company_mast.com_name; \ No newline at end of file diff --git a/sql/Joins/Write a SQL query to display the item name, price, and company name of all the products.sql b/sql/Joins/Write a SQL query to display the item name, price, and company name of all the products.sql new file mode 100644 index 0000000..50ab3ba --- /dev/null +++ b/sql/Joins/Write a SQL query to display the item name, price, and company name of all the products.sql @@ -0,0 +1,5 @@ +/*Write a SQL query to display the item name, price, and company name of all the products.*/ +SELECT item_mast.pro_name, pro_price, company_mast.com_name + FROM item_mast + INNER JOIN company_mast + ON item_mast.pro_com = company_mast.com_id; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to find the details of a order i.e. order number, order date, amount of order, which customer gives the order and which salesman works for that customer.sql b/sql/Joins/Write a SQL statement to find the details of a order i.e. order number, order date, amount of order, which customer gives the order and which salesman works for that customer.sql new file mode 100644 index 0000000..b06dc35 --- /dev/null +++ b/sql/Joins/Write a SQL statement to find the details of a order i.e. order number, order date, amount of order, which customer gives the order and which salesman works for that customer.sql @@ -0,0 +1,10 @@ +/*Write a SQL statement to find the details of a order i.e. order number, order date, amount of order, which customer gives the + order and which salesman works for that customer and how much commission he gets for an order.*/ +SELECT a.ord_no,a.ord_date,a.purch_amt, +b.cust_name AS "Customer Name", b.grade, +c.name AS "Salesman", c.commission +FROM orders a +INNER JOIN customer b +ON a.customer_id=b.customer_id +INNER JOIN salesman c +ON a.salesman_id=c.salesman_id; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to find the list of customers who appointed a salesman for their jobs who does not live in the same city where their customer lives, and gets a commission is above 12%.sql b/sql/Joins/Write a SQL statement to find the list of customers who appointed a salesman for their jobs who does not live in the same city where their customer lives, and gets a commission is above 12%.sql new file mode 100644 index 0000000..8102ec1 --- /dev/null +++ b/sql/Joins/Write a SQL statement to find the list of customers who appointed a salesman for their jobs who does not live in the same city where their customer lives, and gets a commission is above 12%.sql @@ -0,0 +1,9 @@ +/*Write a SQL statement to find the list of customers who appointed a salesman for their jobs who does not live in the same +city where their customer lives, and gets a commission is above 12%.*/ +SELECT a.cust_name AS "Customer Name", +a.city, b.name AS "Salesman", b.city,b.commission +FROM customer a +INNER JOIN salesman b +ON a.salesman_id=b.salesman_id +WHERE b.commission>.12 +AND a.city<>b.city; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to find the list of customers who appointed a salesman for their jobs who gets a commission from the company is more than 12%.sql b/sql/Joins/Write a SQL statement to find the list of customers who appointed a salesman for their jobs who gets a commission from the company is more than 12%.sql new file mode 100644 index 0000000..6099863 --- /dev/null +++ b/sql/Joins/Write a SQL statement to find the list of customers who appointed a salesman for their jobs who gets a commission from the company is more than 12%.sql @@ -0,0 +1,8 @@ +/*Write a SQL statement to find the list of customers who appointed a salesman for their jobs who gets a commission from the + company is more than 12%.*/ +SELECT a.cust_name AS "Customer Name", +a.city, b.name AS "Salesman", b.commission +FROM customer a +INNER JOIN salesman b +ON a.salesman_id=b.salesman_id +WHERE b.commission>.12; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to know which salesman are working for which customer.sql b/sql/Joins/Write a SQL statement to know which salesman are working for which customer.sql new file mode 100644 index 0000000..6a03ffd --- /dev/null +++ b/sql/Joins/Write a SQL statement to know which salesman are working for which customer.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to know which salesman are working for which customer.*/ +SELECT a.cust_name AS "Customer Name", +a.city, b.name AS "Salesman", b.commission +FROM customer a +INNER JOIN salesman b +ON a.salesman_id=b.salesman_id; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for that customer who belongs to a city.sql b/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for that customer who belongs to a city.sql new file mode 100644 index 0000000..733752b --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for that customer who belongs to a city.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all + customer and vice versa for that customer who belongs to a city. */ +SELECT * +FROM salesman a +CROSS JOIN customer b +WHERE a.city IS NOT NULL; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for those salesmen who belongs.sql b/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for those salesmen who belongs.sql new file mode 100644 index 0000000..acd3857 --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for those salesmen who belongs.sql @@ -0,0 +1,7 @@ +/*Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all +customer and vice versa for those salesmen who belongs to a city and the customers who must have a grade.*/ +SELECT * +FROM salesman a +CROSS JOIN customer b +WHERE a.city IS NOT NULL +AND b.grade IS NOT NULL; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for those salesmen who must belong a city.sql b/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for those salesmen who must belong a city.sql new file mode 100644 index 0000000..07298ee --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all customer and vice versa for those salesmen who must belong a city.sql @@ -0,0 +1,9 @@ +/*Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all +customer and vice versa for those salesmen who must belong a city which is not the same as his customer and the customers +should have an own grade.*/ +SELECT * +FROM salesman a +CROSS JOIN customer b +WHERE a.city IS NOT NULL +AND b.grade IS NOT NULL +AND a.city<>b.city; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman.sql b/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman.sql new file mode 100644 index 0000000..1638fa4 --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to make a cartesian product between salesman and customer i.e. each salesman will appear for all +customer and vice versa.*/ +SELECT * +FROM salesman a +CROSS JOIN customer b; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a join on the tables salesman, customer and orders in such a form that the same column of each table will appear once and only the relational rows will come.sql b/sql/Joins/Write a SQL statement to make a join on the tables salesman, customer and orders in such a form that the same column of each table will appear once and only the relational rows will come.sql new file mode 100644 index 0000000..5780efc --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a join on the tables salesman, customer and orders in such a form that the same column of each table will appear once and only the relational rows will come.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to make a join on the tables salesman, customer and orders in such a form that the same column of each + table will appear once and only the relational rows will come.*/ +SELECT * +FROM orders +NATURAL JOIN customer +NATURAL JOIN salesman; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a list for the salesmen who either work for one or more customers or yet to join any of the customer.sql b/sql/Joins/Write a SQL statement to make a list for the salesmen who either work for one or more customers or yet to join any of the customer.sql new file mode 100644 index 0000000..f236f74 --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a list for the salesmen who either work for one or more customers or yet to join any of the customer.sql @@ -0,0 +1,13 @@ +/*Write a SQL statement to make a list for the salesmen who either work for one or more customers or yet to join any of the + customer. The customer, may have placed, either one or more orders on or above order amount 2000 and must have a grade, or + he may not have placed any order to the associated supplier.*/ +SELECT a.cust_name,a.city,a.grade, +b.name AS "Salesman", +c.ord_no, c.ord_date, c.purch_amt +FROM customer a +RIGHT OUTER JOIN salesman b +ON b.salesman_id=a.salesman_id +RIGHT OUTER JOIN orders c +ON c.customer_id=a.customer_id +WHERE c.purch_amt>=2000 +AND a.grade IS NOT NULL; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a list for the salesmen who works either for one or more customer or not yet join under any of the customers.sql b/sql/Joins/Write a SQL statement to make a list for the salesmen who works either for one or more customer or not yet join under any of the customers.sql new file mode 100644 index 0000000..9bf50ab --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a list for the salesmen who works either for one or more customer or not yet join under any of the customers.sql @@ -0,0 +1,10 @@ +/*Write a SQL statement to make a list for the salesmen who works either for one or more customer or not yet join under any of +the customers who placed either one or more orders or no order to their supplier.*/ +SELECT a.cust_name,a.city,a.grade, +b.name AS "Salesman", +c.ord_no, c.ord_date, c.purch_amt +FROM customer a +RIGHT OUTER JOIN salesman b +ON b.salesman_id=a.salesman_id +RIGHT OUTER JOIN orders c +ON c.customer_id=a.customer_id; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a list in ascending order for the customer who holds a grade less than 300 and works either through a salesman or by own.sql b/sql/Joins/Write a SQL statement to make a list in ascending order for the customer who holds a grade less than 300 and works either through a salesman or by own.sql new file mode 100644 index 0000000..cba16f6 --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a list in ascending order for the customer who holds a grade less than 300 and works either through a salesman or by own.sql @@ -0,0 +1,9 @@ +/*Write a SQL statement to make a list in ascending order for the customer who holds a grade less than 300 and works either + through a salesman or by own.*/ +SELECT a.cust_name,a.city,a.grade, +b.name AS "Salesman", b.city +FROM customer a +LEFT OUTER JOIN salesman b +ON a.salesman_id=b.salesman_id +WHERE a.grade<300 +ORDER BY a.customer_id; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a list in ascending order for the customer who works either through a salesman or by own.sql b/sql/Joins/Write a SQL statement to make a list in ascending order for the customer who works either through a salesman or by own.sql new file mode 100644 index 0000000..68757f7 --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a list in ascending order for the customer who works either through a salesman or by own.sql @@ -0,0 +1,7 @@ +/*Write a SQL statement to make a list in ascending order for the customer who works either through a salesman or by own.*/ +SELECT a.cust_name,a.city,a.grade, +b.name AS "Salesman",b.city +FROM customer a +LEFT JOIN salesman b +ON a.salesman_id=b.salesman_id +order by a.customer_id; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a list in ascending order for the salesmen who works either for one or more customer or not yet join under any of the customers.sql b/sql/Joins/Write a SQL statement to make a list in ascending order for the salesmen who works either for one or more customer or not yet join under any of the customers.sql new file mode 100644 index 0000000..6d76019 --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a list in ascending order for the salesmen who works either for one or more customer or not yet join under any of the customers.sql @@ -0,0 +1,8 @@ +/*Write a SQL statement to make a list in ascending order for the salesmen who works either for one or more customer or not + yet join under any of the customers.*/ +SELECT a.cust_name,a.city,a.grade, +b.name AS "Salesman", b.city +FROM customer a +RIGHT OUTER JOIN salesman b +ON b.salesman_id=a.salesman_id +ORDER BY b.salesman_id; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a list with order no, purchase amount, customer name and their cities for those orders which order amount between 500 and 2000.sql b/sql/Joins/Write a SQL statement to make a list with order no, purchase amount, customer name and their cities for those orders which order amount between 500 and 2000.sql new file mode 100644 index 0000000..3d2abda --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a list with order no, purchase amount, customer name and their cities for those orders which order amount between 500 and 2000.sql @@ -0,0 +1,7 @@ +/*Write a SQL statement to make a list with order no, purchase amount, customer name and their cities for those orders which + order amount between 500 and 2000.*/ +SELECT a.ord_no,a.purch_amt, +b.cust_name,b.city +FROM orders a,customer b +WHERE a.customer_id=b.customer_id +AND a.purch_amt BETWEEN 500 AND 2000; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for only those customers on the list who must have a grade and placed.sql b/sql/Joins/Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for only those customers on the list who must have a grade and placed.sql new file mode 100644 index 0000000..2770cd3 --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for only those customers on the list who must have a grade and placed.sql @@ -0,0 +1,9 @@ +/*Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for only those customers +on the list who must have a grade and placed one or more orders or which order(s) have been placed by the customer who is neither +in the list not have a grade.*/ +SELECT a.cust_name,a.city, b.ord_no, +b.ord_date,b.purch_amt AS "Order Amount" +FROM customer a +FULL OUTER JOIN orders b +ON a.customer_id=b.customer_id +WHERE a.grade IS NOT NULL; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for those customers from the existing list who placed one or more orders.sql b/sql/Joins/Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for those customers from the existing list who placed one or more orders.sql new file mode 100644 index 0000000..80746c9 --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for those customers from the existing list who placed one or more orders.sql @@ -0,0 +1,7 @@ +/*Write a SQL statement to make a report with customer name, city, order no. order date, purchase amount for those customers +from the existing list who placed one or more orders or which order(s) have been placed by the customer who is not on the list*/ +SELECT a.cust_name,a.city, b.ord_no, +b.ord_date,b.purch_amt AS "Order Amount" +FROM customer a +FULL OUTER JOIN orders b +ON a.customer_id=b.customer_id; diff --git a/sql/Joins/Write a SQL statement to make a report with customer name, city, order number, order date, and order amount in ascending order according to the order date.sql b/sql/Joins/Write a SQL statement to make a report with customer name, city, order number, order date, and order amount in ascending order according to the order date.sql new file mode 100644 index 0000000..cf458f2 --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a report with customer name, city, order number, order date, and order amount in ascending order according to the order date.sql @@ -0,0 +1,9 @@ +/* Write a SQL statement to make a report with customer name, city, order number, order date, and order amount in ascending +order according to the order date to find that either any of the existing customers have placed no order or placed one or more + orders.*/ + SELECT a.cust_name,a.city, b.ord_no, + b.ord_date,b.purch_amt AS "Order Amount" + FROM customer a + LEFT OUTER JOIN orders b + ON a.customer_id=b.customer_id + order by b.ord_date; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to make a report with customer name, city, order number, order date, order amount salesman name and commission to find that either any of the existing customers.sql b/sql/Joins/Write a SQL statement to make a report with customer name, city, order number, order date, order amount salesman name and commission to find that either any of the existing customers.sql new file mode 100644 index 0000000..7615e6c --- /dev/null +++ b/sql/Joins/Write a SQL statement to make a report with customer name, city, order number, order date, order amount salesman name and commission to find that either any of the existing customers.sql @@ -0,0 +1,11 @@ +/*Write a SQL statement to make a report with customer name, city, order number, order date, order amount salesman name and +commission to find that either any of the existing customers have placed no order or placed one or more orders by their salesman + or by own. */ +SELECT a.cust_name,a.city, b.ord_no, +b.ord_date,b.purch_amt AS "Order Amount", +c.name,c.commission +FROM customer a +LEFT OUTER JOIN orders b +ON a.customer_id=b.customer_id +LEFT OUTER JOIN salesman c +ON c.salesman_id=b.salesman_id; \ No newline at end of file diff --git a/sql/Joins/Write a SQL statement to prepare a list with salesman name, customer name and their cities for the salesmen and customer who belongs to the same city.sql b/sql/Joins/Write a SQL statement to prepare a list with salesman name, customer name and their cities for the salesmen and customer who belongs to the same city.sql new file mode 100644 index 0000000..faa6601 --- /dev/null +++ b/sql/Joins/Write a SQL statement to prepare a list with salesman name, customer name and their cities for the salesmen and customer who belongs to the same city.sql @@ -0,0 +1,6 @@ +/*Write a SQL statement to prepare a list with salesman name, customer name and their cities for the salesmen and customer who +belongs to the same city.*/ +SELECT salesman.name AS "Salesman", +customer.cust_name, customer.city +FROM salesman,customer +WHERE salesman.city=customer.city; \ No newline at end of file diff --git a/sql/QueryMultipleTables/Write a SQL statement that finds out each order number followed by the name of the customers who made the order.sql b/sql/QueryMultipleTables/Write a SQL statement that finds out each order number followed by the name of the customers who made the order.sql new file mode 100644 index 0000000..1714b6a --- /dev/null +++ b/sql/QueryMultipleTables/Write a SQL statement that finds out each order number followed by the name of the customers who made the order.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement that finds out each order number followed by the name of the customers who made the order. */ +SELECT orders.ord_no, customer.cust_name +FROM orders, customer +WHERE orders.customer_id = customer.customer_id; \ No newline at end of file diff --git a/sql/QueryMultipleTables/Write a SQL statement that produces all orders with the order number, customer name, commission rate and earned commission amount for those customers.sql b/sql/QueryMultipleTables/Write a SQL statement that produces all orders with the order number, customer name, commission rate and earned commission amount for those customers.sql new file mode 100644 index 0000000..fce768b --- /dev/null +++ b/sql/QueryMultipleTables/Write a SQL statement that produces all orders with the order number, customer name, commission rate and earned commission amount for those customers.sql @@ -0,0 +1,8 @@ +/*Write a SQL statement that produces all orders with the order number, customer name, commission rate and +earned commission amount for those customers who carry their grade more than 200 and served by an existing salesman.*/ +SELECT ord_no, cust_name, commission AS "Commission%", +purch_amt*commission AS "Commission" +FROM salesman,orders,customer +WHERE orders.customer_id = customer.customer_id +AND orders.salesman_id = salesman.salesman_id +AND customer.grade>=200; \ No newline at end of file diff --git a/sql/QueryMultipleTables/Write a SQL statement that shorts out the customer and their grade who made an order. Each of the customers must have a grade and served.sql b/sql/QueryMultipleTables/Write a SQL statement that shorts out the customer and their grade who made an order. Each of the customers must have a grade and served.sql new file mode 100644 index 0000000..fb4faa8 --- /dev/null +++ b/sql/QueryMultipleTables/Write a SQL statement that shorts out the customer and their grade who made an order. Each of the customers must have a grade and served.sql @@ -0,0 +1,9 @@ +/*Write a SQL statement that shorts out the customer and their grade who made an order. Each of the customers +must have a grade and served by at least a salesman, who belongs to a city.*/ +SELECT customer.cust_name AS "Customer", +customer.grade AS "Grade" +FROM orders, salesman, customer +WHERE orders.customer_id = customer.customer_id +AND orders.salesman_id = salesman.salesman_id +AND salesman.city IS NOT NULL +AND customer.grade IS NOT NULL; \ No newline at end of file diff --git a/sql/QueryMultipleTables/Write a SQL statement to find the names of all customers along with the salesmen who works for them.sql b/sql/QueryMultipleTables/Write a SQL statement to find the names of all customers along with the salesmen who works for them.sql new file mode 100644 index 0000000..30c5eac --- /dev/null +++ b/sql/QueryMultipleTables/Write a SQL statement to find the names of all customers along with the salesmen who works for them.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find the names of all customers along with the salesmen who works for them.*/ +SELECT customer.cust_name, salesman.name +FROM customer,salesman +WHERE salesman.salesman_id = customer.salesman_id; \ No newline at end of file diff --git a/sql/QueryMultipleTables/Write a query to find those customers with their name and those salesmen with their name and city who lives in the same city.sql b/sql/QueryMultipleTables/Write a query to find those customers with their name and those salesmen with their name and city who lives in the same city.sql new file mode 100644 index 0000000..611e291 --- /dev/null +++ b/sql/QueryMultipleTables/Write a query to find those customers with their name and those salesmen with their name and city who lives in the same city.sql @@ -0,0 +1,6 @@ +/*Write a query to find those customers with their name and those salesmen with their name and city +who lives in the same city.*/ +SELECT customer.cust_name, +salesman.name, salesman.city +FROM salesman, customer +WHERE salesman.city = customer.city; \ No newline at end of file diff --git a/sql/README.md b/sql/README.md new file mode 100644 index 0000000..bfd4e53 --- /dev/null +++ b/sql/README.md @@ -0,0 +1,3 @@ +# SQL query language + +SQL files are used by database products. A SQL file typically contains queries to modify the structure of a relational database -- to insert, delete, update or extract data. SQL files are compatible with many database programs. \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to calculate the average price of all products of the manufacturer which code is l6.sql b/sql/RetrieveFromTables/Write a SQL query to calculate the average price of all products of the manufacturer which code is l6.sql new file mode 100644 index 0000000..c6a3d9d --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to calculate the average price of all products of the manufacturer which code is l6.sql @@ -0,0 +1,3 @@ +/*Write a SQL query to calculate the average price of all products of the manufacturer which code is l6.*/ +SELECT AVG(pro_price) FROM item_mast + WHERE pro_com=16; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to display the Nobel prizes for 1970.sql b/sql/RetrieveFromTables/Write a SQL query to display the Nobel prizes for 1970.sql new file mode 100644 index 0000000..a3faf57 --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to display the Nobel prizes for 1970.sql @@ -0,0 +1,4 @@ +/*Write a SQL query to display the Nobel prizes for 1970.*/ + SELECT year,subject,winner + FROM nobel_win + WHERE year=1970; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to display the average price of the items for each company, showing only the company code.sql b/sql/RetrieveFromTables/Write a SQL query to display the average price of the items for each company, showing only the company code.sql new file mode 100644 index 0000000..095b3ea --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to display the average price of the items for each company, showing only the company code.sql @@ -0,0 +1,4 @@ +/*Write a SQL query to display the average price of the items for each company, showing only the company code.*/ + SELECT AVG(pro_price), pro_com + FROM item_mast + GROUP BY pro_com; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to display the year and subject that won 'Dennis Gabor' his prize.sql b/sql/RetrieveFromTables/Write a SQL query to display the year and subject that won 'Dennis Gabor' his prize.sql new file mode 100644 index 0000000..43d4982 --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to display the year and subject that won 'Dennis Gabor' his prize.sql @@ -0,0 +1,3 @@ +SELECT year, subject + FROM nobel_win + WHERE winner = 'Dennis Gabor'; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to find all details of the prize won by Johannes Georg Bednorz.sql b/sql/RetrieveFromTables/Write a SQL query to find all details of the prize won by Johannes Georg Bednorz.sql new file mode 100644 index 0000000..a9e781d --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to find all details of the prize won by Johannes Georg Bednorz.sql @@ -0,0 +1,4 @@ +/* Write a SQL query to find all details of the prize won by Johannes Georg Bednorz.*/ +SELECT * + FROM nobel_win + WHERE winner='Johannes Georg Bednorz'; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to find all the details of 1970 winners by the ordered to subject and winner name; but the list contain the subject Economics and Chemistry at last.sql b/sql/RetrieveFromTables/Write a SQL query to find all the details of 1970 winners by the ordered to subject and winner name; but the list contain the subject Economics and Chemistry at last.sql new file mode 100644 index 0000000..d4f3faf --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to find all the details of 1970 winners by the ordered to subject and winner name; but the list contain the subject Economics and Chemistry at last.sql @@ -0,0 +1,12 @@ +/* Write a SQL query to find all the details of 1970 winners by the ordered to subject and winner name; + but the list contain the subject Economics and Chemistry at last.*/ + SELECT * +FROM nobel_win +WHERE year=1970 +ORDER BY + CASE + WHEN subject IN ('Economics','Chemistry') THEN 1 + ELSE 0 + END ASC, + subject, + winner; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to find all the products with a price between Rs.200 and Rs.600.sql b/sql/RetrieveFromTables/Write a SQL query to find all the products with a price between Rs.200 and Rs.600.sql new file mode 100644 index 0000000..b0d5b7a --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to find all the products with a price between Rs.200 and Rs.600.sql @@ -0,0 +1,3 @@ +/*Write a SQL query to find all the products with a price between Rs.200 and Rs.600.*/ + SELECT * FROM item_mast + WHERE pro_price BETWEEN 200 AND 600; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to find the item name and price in Rs.sql b/sql/RetrieveFromTables/Write a SQL query to find the item name and price in Rs.sql new file mode 100644 index 0000000..d71b700 --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to find the item name and price in Rs.sql @@ -0,0 +1,3 @@ +/*Write a SQL query to find the item name and price in Rs.*/ +SELECT pro_name as "Item Name", pro_price AS "Price in Rs." + FROM item_mast; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to find the name and price of the cheapest item.sql b/sql/RetrieveFromTables/Write a SQL query to find the name and price of the cheapest item.sql new file mode 100644 index 0000000..9efd47d --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to find the name and price of the cheapest item.sql @@ -0,0 +1,5 @@ +/*Write a SQL query to find the name and price of the cheapest item.*/ +SELECT pro_name, pro_price + FROM item_mast + WHERE pro_price = + (SELECT MIN(pro_price) FROM item_mast); \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to give the name of the 'Physics' winners since the year 1950.sql b/sql/RetrieveFromTables/Write a SQL query to give the name of the 'Physics' winners since the year 1950.sql new file mode 100644 index 0000000..a296403 --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to give the name of the 'Physics' winners since the year 1950.sql @@ -0,0 +1,5 @@ +/*Write a SQL query to give the name of the 'Physics' winners since the year 1950.*/ +SELECT winner +FROM nobel_win +WHERE year>=1950 +AND subject='Physics'; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to know the winner of the 1971 prize for Literature.sql b/sql/RetrieveFromTables/Write a SQL query to know the winner of the 1971 prize for Literature.sql new file mode 100644 index 0000000..e0ec525 --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to know the winner of the 1971 prize for Literature.sql @@ -0,0 +1,5 @@ +/*Write a SQL query to know the winner of the 1971 prize for Literature.*/ +SELECT winner + FROM nobel_win + WHERE year = 1971 + AND subject = 'Literature'; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to show all details of the Prime Ministerial winners after 1972 of Menachem Begin and Yitzhak Rabin.sql b/sql/RetrieveFromTables/Write a SQL query to show all details of the Prime Ministerial winners after 1972 of Menachem Begin and Yitzhak Rabin.sql new file mode 100644 index 0000000..8e179ea --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to show all details of the Prime Ministerial winners after 1972 of Menachem Begin and Yitzhak Rabin.sql @@ -0,0 +1,5 @@ +/* Write a SQL query to show all details of the Prime Ministerial winners after 1972 of Menachem Begin and Yitzhak Rabin.*/ +SELECT * FROM nobel_win + WHERE year >1972 + AND winner IN ('Menachem Begin', + 'Yitzhak Rabin'); \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to show all the details (year, subject, winner, country ) of the Chemistry prize winners between the year 1965 to 1975 inclusive.sql b/sql/RetrieveFromTables/Write a SQL query to show all the details (year, subject, winner, country ) of the Chemistry prize winners between the year 1965 to 1975 inclusive.sql new file mode 100644 index 0000000..0f7a483 --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to show all the details (year, subject, winner, country ) of the Chemistry prize winners between the year 1965 to 1975 inclusive.sql @@ -0,0 +1,6 @@ +/*Write a SQL query to show all the details (year, subject, winner, country ) of the Chemistry +prize winners between the year 1965 to 1975 inclusive.*/ +SELECT year, subject, winner, country + FROM nobel_win + WHERE subject = 'Chemistry' + AND year>=1965 AND year<=1975; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to show all the details of the winners with first name Louis.sql b/sql/RetrieveFromTables/Write a SQL query to show all the details of the winners with first name Louis.sql new file mode 100644 index 0000000..6a4e1e8 --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to show all the details of the winners with first name Louis.sql @@ -0,0 +1,4 @@ +/* Write a SQL query to show all the details of the winners with first name Louis. */ +SELECT * + FROM nobel_win + WHERE winner LIKE 'Louis%'; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to show all the winners in Physics for 1970 together with the winner of Economics for 1971.sql b/sql/RetrieveFromTables/Write a SQL query to show all the winners in Physics for 1970 together with the winner of Economics for 1971.sql new file mode 100644 index 0000000..69c1bce --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to show all the winners in Physics for 1970 together with the winner of Economics for 1971.sql @@ -0,0 +1,8 @@ +/* Write a SQL query to show all the winners in Physics for 1970 together with the winner of Economics for 1971.*/ +SELECT * + FROM nobel_win + WHERE (subject ='Physics' AND year=1970) +UNION +SELECT * + FROM nobel_win + WHERE (subject ='Economics' AND year=1971); \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to show all the winners of nobel prize in the year 1970 except the subject Physiology and Economics.sql b/sql/RetrieveFromTables/Write a SQL query to show all the winners of nobel prize in the year 1970 except the subject Physiology and Economics.sql new file mode 100644 index 0000000..7b6c3bf --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to show all the winners of nobel prize in the year 1970 except the subject Physiology and Economics.sql @@ -0,0 +1,5 @@ +/* Write a SQL query to show all the winners of nobel prize in the year 1970 except the subject Physiology and Economics.*/ +SELECT * + FROM nobel_win + WHERE year=1970 + AND subject NOT IN('Physiology','Economics'); \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL query to show the winners of a 'Physiology' prize in an early year before 1971 together with winners of a 'Peace' prize in a later year on and after the 1974.sql b/sql/RetrieveFromTables/Write a SQL query to show the winners of a 'Physiology' prize in an early year before 1971 together with winners of a 'Peace' prize in a later year on and after the 1974.sql new file mode 100644 index 0000000..956be20 --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL query to show the winners of a 'Physiology' prize in an early year before 1971 together with winners of a 'Peace' prize in a later year on and after the 1974.sql @@ -0,0 +1,9 @@ +/* Write a SQL query to show the winners of a 'Physiology' prize in an early year before 1971 together with winners of +a 'Peace' prize in a later year on and after the 1974.*/ +SELECT * + FROM nobel_win + WHERE (subject ='Physiology' AND year<1971) +UNION +SELECT * + FROM nobel_win + WHERE (subject ='Peace' AND year>=1974); \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a SQL statement to display all the information for those customers with a grade of 200.sql b/sql/RetrieveFromTables/Write a SQL statement to display all the information for those customers with a grade of 200.sql new file mode 100644 index 0000000..d821e71 --- /dev/null +++ b/sql/RetrieveFromTables/Write a SQL statement to display all the information for those customers with a grade of 200.sql @@ -0,0 +1,3 @@ +/*Write a SQL statement to display all the information for those customers with a grade of 200.*/ +SELECT *FROM customer +WHERE grade=200; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query in SQL to display all the data of employees that work in the department 57.sql b/sql/RetrieveFromTables/Write a query in SQL to display all the data of employees that work in the department 57.sql new file mode 100644 index 0000000..f6f6fd3 --- /dev/null +++ b/sql/RetrieveFromTables/Write a query in SQL to display all the data of employees that work in the department 57.sql @@ -0,0 +1,4 @@ +/*Write a query in SQL to display all the data of employees that work in the department 57.*/ +SELECT * + FROM emp_details + WHERE emp_dept= 57; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query in SQL to find the data of employees whose last name is 'Snares'.sql b/sql/RetrieveFromTables/Write a query in SQL to find the data of employees whose last name is 'Snares'.sql new file mode 100644 index 0000000..964c48b --- /dev/null +++ b/sql/RetrieveFromTables/Write a query in SQL to find the data of employees whose last name is 'Snares'.sql @@ -0,0 +1,4 @@ +/*Write a query in SQL to find the data of employees whose last name is 'Snares'.*/ +SELECT * + FROM emp_details + WHERE emp_lname= 'Snares'; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query in SQL to find the last name of all employees, without duplicates.sql b/sql/RetrieveFromTables/Write a query in SQL to find the last name of all employees, without duplicates.sql new file mode 100644 index 0000000..22eaf7b --- /dev/null +++ b/sql/RetrieveFromTables/Write a query in SQL to find the last name of all employees, without duplicates.sql @@ -0,0 +1,3 @@ +/*Write a query in SQL to find the last name of all employees, without duplicates.*/ +SELECT DISTINCT emp_lname +FROM emp_details; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query to display a string This is SQL Exercise, Practice and Solution.sql b/sql/RetrieveFromTables/Write a query to display a string This is SQL Exercise, Practice and Solution.sql new file mode 100644 index 0000000..dcc1e5a --- /dev/null +++ b/sql/RetrieveFromTables/Write a query to display a string This is SQL Exercise, Practice and Solution.sql @@ -0,0 +1,2 @@ +/*Write a query to display a string "This is SQL Exercise, Practice and Solution".*/ +SELECT "This is SQL Exercise, Practice and Solution"; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query to display all the columns from salesman table.sql b/sql/RetrieveFromTables/Write a query to display all the columns from salesman table.sql new file mode 100644 index 0000000..7052980 --- /dev/null +++ b/sql/RetrieveFromTables/Write a query to display all the columns from salesman table.sql @@ -0,0 +1,16 @@ +/*Write a query to display all the columns from salesman table.*/ +/*SELECT [DISTINCT] [.] |*| + +[AS ],... +FROM | + +[[AS] ] +[WHERE ] +[GROUP BY [.],... +[HAVING ] +] +[ORDER_BY | + +[ASC | DESC],... +];*/ + SELECT * FROM salesman; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query to display names and city of salesman, who belongs to the city of Paris.sql b/sql/RetrieveFromTables/Write a query to display names and city of salesman, who belongs to the city of Paris.sql new file mode 100644 index 0000000..e262ca3 --- /dev/null +++ b/sql/RetrieveFromTables/Write a query to display names and city of salesman, who belongs to the city of Paris.sql @@ -0,0 +1,4 @@ +/*Write a query to display names and city of salesman, who belongs to the city of Paris. */ +SELECT name,city +FROM salesman +WHERE city='Paris'; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query to display only name and commission from table salesman.sql b/sql/RetrieveFromTables/Write a query to display only name and commission from table salesman.sql new file mode 100644 index 0000000..c61818d --- /dev/null +++ b/sql/RetrieveFromTables/Write a query to display only name and commission from table salesman.sql @@ -0,0 +1,2 @@ + SELECT name, commission + FROM salesman; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query to display salesman_id, salesman name, order date, order no, and purchase amount from orders table.sql b/sql/RetrieveFromTables/Write a query to display salesman_id, salesman name, order date, order no, and purchase amount from orders table.sql new file mode 100644 index 0000000..f6aeaf4 --- /dev/null +++ b/sql/RetrieveFromTables/Write a query to display salesman_id, salesman name, order date, order no, and purchase amount from orders table.sql @@ -0,0 +1,3 @@ +/*Write a query to display salesman_id, salesman name, order date, order no, and purchase amount from orders table. */ +SELECT ord_date, salesman_id, ord_no, purch_amt +FROM orders; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query to display sum of two numbers 10 and 15.sql b/sql/RetrieveFromTables/Write a query to display sum of two numbers 10 and 15.sql new file mode 100644 index 0000000..553593c --- /dev/null +++ b/sql/RetrieveFromTables/Write a query to display sum of two numbers 10 and 15.sql @@ -0,0 +1,2 @@ +/*Write a query to display sum of two numbers 10 and 15.*/ +SELECT 10 + 15; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query to display the result of an arithmetic simplification.sql b/sql/RetrieveFromTables/Write a query to display the result of an arithmetic simplification.sql new file mode 100644 index 0000000..2101e46 --- /dev/null +++ b/sql/RetrieveFromTables/Write a query to display the result of an arithmetic simplification.sql @@ -0,0 +1,2 @@ +/*Write a query to display the result of an arithmetic simplification.*/ + SELECT 10 + 15 - 5 * 2; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query to display three numbers in three columns.sql b/sql/RetrieveFromTables/Write a query to display three numbers in three columns.sql new file mode 100644 index 0000000..1205963 --- /dev/null +++ b/sql/RetrieveFromTables/Write a query to display three numbers in three columns.sql @@ -0,0 +1,2 @@ +/*Write a query to display three numbers in three columns.*/ +SELECT 5, 10, 15; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a query which will retrieve the values of salesman id of all salesmen, getting orders from the customers in orders table without any repeats.sql b/sql/RetrieveFromTables/Write a query which will retrieve the values of salesman id of all salesmen, getting orders from the customers in orders table without any repeats.sql new file mode 100644 index 0000000..cbe7309 --- /dev/null +++ b/sql/RetrieveFromTables/Write a query which will retrieve the values of salesman id of all salesmen, getting orders from the customers in orders table without any repeats.sql @@ -0,0 +1,2 @@ +SELECT DISTINCT salesman_id +FROM orders; \ No newline at end of file diff --git a/sql/RetrieveFromTables/Write a sql query to display the order number followed by order date and the purchase amount for each order which will be delivered by the salesman who is holding the ID 5001.sql b/sql/RetrieveFromTables/Write a sql query to display the order number followed by order date and the purchase amount for each order which will be delivered by the salesman who is holding the ID 5001.sql new file mode 100644 index 0000000..3f55c33 --- /dev/null +++ b/sql/RetrieveFromTables/Write a sql query to display the order number followed by order date and the purchase amount for each order which will be delivered by the salesman who is holding the ID 5001.sql @@ -0,0 +1,5 @@ +/*Write a sql query to display the order number followed by order date and the purchase amount for each order which will + be delivered by the salesman who is holding the ID 5001.*/ + SELECT ord_no, ord_date, purch_amt +FROM orders +WHERE salesman_id=5001; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/1. Write a query in SQL to find the name and year of the movies.sql b/sql/SQLMovieDatabase/1. Write a query in SQL to find the name and year of the movies.sql new file mode 100644 index 0000000..59d2951 --- /dev/null +++ b/sql/SQLMovieDatabase/1. Write a query in SQL to find the name and year of the movies.sql @@ -0,0 +1,3 @@ +/*1. Write a query in SQL to find the name and year of the movies. */ +SELECT mov_title, mov_year +FROM movie; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/10. Write a query in SQL to find the list of all those movies with year which include the words Boogie Nights.sql b/sql/SQLMovieDatabase/10. Write a query in SQL to find the list of all those movies with year which include the words Boogie Nights.sql new file mode 100644 index 0000000..7a81889 --- /dev/null +++ b/sql/SQLMovieDatabase/10. Write a query in SQL to find the list of all those movies with year which include the words Boogie Nights.sql @@ -0,0 +1,5 @@ +/*10. Write a query in SQL to find the list of all those movies with year which include the words Boogie Nights.*/ +SELECT mov_id, mov_title, mov_year +FROM movie +WHERE mov_title LIKE '%Boogie%Nights%' +ORDER BY mov_year ASC; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/11. Write a query in SQL to find the ID number for the actor whose first name is 'Woody' and the last name is 'Allen'.sql b/sql/SQLMovieDatabase/11. Write a query in SQL to find the ID number for the actor whose first name is 'Woody' and the last name is 'Allen'.sql new file mode 100644 index 0000000..002bfc3 --- /dev/null +++ b/sql/SQLMovieDatabase/11. Write a query in SQL to find the ID number for the actor whose first name is 'Woody' and the last name is 'Allen'.sql @@ -0,0 +1,5 @@ +/*11. Write a query in SQL to find the ID number for the actor whose first name is 'Woody' and the last name is 'Allen'.*/ +SELECT act_id +FROM actor +WHERE act_fname='Woody' +AND act_lname='Allen'; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/12. Write a query in SQL to list all the information of the actors who played a role in the movie 'Annie Hall'.sql b/sql/SQLMovieDatabase/12. Write a query in SQL to list all the information of the actors who played a role in the movie 'Annie Hall'.sql new file mode 100644 index 0000000..059a1f7 --- /dev/null +++ b/sql/SQLMovieDatabase/12. Write a query in SQL to list all the information of the actors who played a role in the movie 'Annie Hall'.sql @@ -0,0 +1,11 @@ +/*12. Write a query in SQL to list all the information of the actors who played a role in the movie 'Annie Hall'.*/ +SELECT * +FROM actor +WHERE act_id IN( +SELECT act_id +FROM movie_cast +WHERE mov_id IN ( +SELECT mov_id +FROM movie +WHERE mov_title='Annie Hall' +)); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/13. Write a query in SQL to list the first and last names of all the actors who were cast in the movie 'Annie Hall', and the roles they played in that production.sql b/sql/SQLMovieDatabase/13. Write a query in SQL to list the first and last names of all the actors who were cast in the movie 'Annie Hall', and the roles they played in that production.sql new file mode 100644 index 0000000..2d38529 --- /dev/null +++ b/sql/SQLMovieDatabase/13. Write a query in SQL to list the first and last names of all the actors who were cast in the movie 'Annie Hall', and the roles they played in that production.sql @@ -0,0 +1,7 @@ +/*13. Write a query in SQL to list the first and last names of all the actors who were cast in the movie 'Annie Hall', and + the roles they played in that production.*/ + SELECT act_fname,act_lname,role + FROM actor + JOIN movie_cast ON actor.act_id=movie_cast.act_id + JOIN movie ON movie_cast.mov_id=movie.mov_id + AND movie.mov_title='Annie Hall'; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/14. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a role for 'Eyes Wide Shut'.sql b/sql/SQLMovieDatabase/14. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a role for 'Eyes Wide Shut'.sql new file mode 100644 index 0000000..b9ecf64 --- /dev/null +++ b/sql/SQLMovieDatabase/14. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a role for 'Eyes Wide Shut'.sql @@ -0,0 +1,9 @@ +/*14. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a +role for 'Eyes Wide Shut'.*/ +SELECT dir_fname, dir_lname, mov_title +FROM director +NATURAL JOIN movie_direction +NATURAL JOIN movie +NATURAL JOIN movie_cast +WHERE role IS NOT NULL +AND mov_title='Eyes Wide Shut'; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/15. Write a query in SQL to find the name of the director (first and last names) who directed a movie that casted a role for 'Eyes Wide Shut'.sql b/sql/SQLMovieDatabase/15. Write a query in SQL to find the name of the director (first and last names) who directed a movie that casted a role for 'Eyes Wide Shut'.sql new file mode 100644 index 0000000..82953ba --- /dev/null +++ b/sql/SQLMovieDatabase/15. Write a query in SQL to find the name of the director (first and last names) who directed a movie that casted a role for 'Eyes Wide Shut'.sql @@ -0,0 +1,16 @@ +/*15. Write a query in SQL to find the name of the director (first and last names) who directed a movie that casted a role +for 'Eyes Wide Shut'.*/ +SELECT dir_fname, dir_lname +FROM director +WHERE dir_id in ( +SELECT dir_id +FROM movie_direction +WHERE mov_id in( +SELECT mov_id +FROM movie_cast WHERE role = ANY ( +SELECT role +FROM movie_cast +WHERE mov_id IN ( +SELECT mov_id +FROM movie +WHERE mov_title='Eyes Wide Shut')))); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/16. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a role as Sean Maguire.sql b/sql/SQLMovieDatabase/16. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a role as Sean Maguire.sql new file mode 100644 index 0000000..9be1ea1 --- /dev/null +++ b/sql/SQLMovieDatabase/16. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a role as Sean Maguire.sql @@ -0,0 +1,11 @@ +/*16. Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a + role as Sean Maguire.*/ +SELECT dir_fname, dir_lname, mov_title +FROM director +JOIN movie_direction + ON director.dir_id=movie_direction.dir_id +JOIN movie + ON movie_direction.mov_id=movie.mov_id +JOIN movie_cast + ON movie_cast.mov_id=movie.mov_id + WHERE role='Sean Maguire'; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/17. Write a query in SQL to list all the actors who acted in a movie before 1990 and also in a movie after 2000.sql b/sql/SQLMovieDatabase/17. Write a query in SQL to list all the actors who acted in a movie before 1990 and also in a movie after 2000.sql new file mode 100644 index 0000000..9dafe48 --- /dev/null +++ b/sql/SQLMovieDatabase/17. Write a query in SQL to list all the actors who acted in a movie before 1990 and also in a movie after 2000.sql @@ -0,0 +1,8 @@ +/*17. Write a query in SQL to list all the actors who acted in a movie before 1990 and also in a movie after 2000.*/ +SELECT act_fname, act_lname, mov_title, mov_year +FROM actor +JOIN movie_cast +ON actor.act_id=movie_cast.act_id +JOIN movie +ON movie_cast.mov_id=movie.mov_id +WHERE mov_year NOT BETWEEN 1990 and 2000; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/18. Write a query in SQL to list first and last name of all the directors with number of genres movies they directed with genres name, and arranged.sql b/sql/SQLMovieDatabase/18. Write a query in SQL to list first and last name of all the directors with number of genres movies they directed with genres name, and arranged.sql new file mode 100644 index 0000000..ca6380a --- /dev/null +++ b/sql/SQLMovieDatabase/18. Write a query in SQL to list first and last name of all the directors with number of genres movies they directed with genres name, and arranged.sql @@ -0,0 +1,9 @@ +/*18. Write a query in SQL to list first and last name of all the directors with number of genres movies they directed with + genres name, and arranged the result alphabetically with the first and last name of the director.*/ +SELECT dir_fname,dir_lname, gen_title,count(gen_title) +FROM director +NATURAL JOIN movie_direction +NATURAL JOIN movie_genres +NATURAL JOIN genres +GROUP BY dir_fname, dir_lname,gen_title +ORDER BY dir_fname,dir_lname; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/19. Write a query in SQL to list all the movies with year and genres.sql b/sql/SQLMovieDatabase/19. Write a query in SQL to list all the movies with year and genres.sql new file mode 100644 index 0000000..b829e09 --- /dev/null +++ b/sql/SQLMovieDatabase/19. Write a query in SQL to list all the movies with year and genres.sql @@ -0,0 +1,5 @@ +/*19. Write a query in SQL to list all the movies with year and genres.*/ + SELECT mov_title, mov_year, gen_title + FROM movie + NATURAL JOIN movie_genres + NATURAL JOIN genres; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/2. Write a query in SQL to find the year when the movie American Beauty released.sql b/sql/SQLMovieDatabase/2. Write a query in SQL to find the year when the movie American Beauty released.sql new file mode 100644 index 0000000..fc5085f --- /dev/null +++ b/sql/SQLMovieDatabase/2. Write a query in SQL to find the year when the movie American Beauty released.sql @@ -0,0 +1,4 @@ +/*2. Write a query in SQL to find the year when the movie American Beauty released. */ +SELECT mov_year +FROM movie +WHERE mov_title='American Beauty'; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/20. Write a query in SQL to list all the movies with year, genres, and name of the director.sql b/sql/SQLMovieDatabase/20. Write a query in SQL to list all the movies with year, genres, and name of the director.sql new file mode 100644 index 0000000..7cb2007 --- /dev/null +++ b/sql/SQLMovieDatabase/20. Write a query in SQL to list all the movies with year, genres, and name of the director.sql @@ -0,0 +1,7 @@ +/*20. Write a query in SQL to list all the movies with year, genres, and name of the director.*/ +SELECT mov_title, mov_year, gen_title, dir_fname, dir_lname +FROM movie +NATURAL JOIN movie_genres +NATURAL JOIN genres +NATURAL JOIN movie_direction +NATURAL JOIN director; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/21. Write a query in SQL to list all the movies which released in the country other than UK.sql b/sql/SQLMovieDatabase/21. Write a query in SQL to list all the movies which released in the country other than UK.sql new file mode 100644 index 0000000..ac30b6d --- /dev/null +++ b/sql/SQLMovieDatabase/21. Write a query in SQL to list all the movies which released in the country other than UK.sql @@ -0,0 +1,6 @@ +/*21. Write a query in SQL to list all the movies which released in the country other than UK.*/ +SELECT mov_title, mov_year, mov_time, +mov_dt_rel AS Date_of_Release, +mov_rel_country AS Releasing_Country +FROM movie +WHERE mov_rel_country<>'UK'; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/22. Write a query in SQL to list all the movies with title, year, date of release, movie duration, and first and last name of the director which released before 1st January 1998.sql b/sql/SQLMovieDatabase/22. Write a query in SQL to list all the movies with title, year, date of release, movie duration, and first and last name of the director which released before 1st January 1998.sql new file mode 100644 index 0000000..15ecba4 --- /dev/null +++ b/sql/SQLMovieDatabase/22. Write a query in SQL to list all the movies with title, year, date of release, movie duration, and first and last name of the director which released before 1st January 1998.sql @@ -0,0 +1,12 @@ +/*22. Write a query in SQL to list all the movies with title, year, date of release, movie duration, and first and last name +of the director which released before 1st January 1989, and sort the result set according to release date from highest date +to lowest.*/ +SELECT movie.mov_title, mov_year, mov_dt_rel, + mov_time,dir_fname, dir_lname +FROM movie +JOIN movie_direction + ON movie.mov_id = movie_direction.mov_id +JOIN director + ON movie_direction.dir_id=director.dir_id +WHERE mov_dt_rel <'01/01/1989' +ORDER BY mov_dt_rel desc; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/23. Write a query in SQL to compute a report which contain the genres of those movies with their average time and number of movies for each genres.sql b/sql/SQLMovieDatabase/23. Write a query in SQL to compute a report which contain the genres of those movies with their average time and number of movies for each genres.sql new file mode 100644 index 0000000..6c080b3 --- /dev/null +++ b/sql/SQLMovieDatabase/23. Write a query in SQL to compute a report which contain the genres of those movies with their average time and number of movies for each genres.sql @@ -0,0 +1,8 @@ +/*23. Write a query in SQL to compute a report which contain the genres of those movies with their average time and number of + movies for each genres.*/ +SELECT gen_title, AVG(mov_time), COUNT(gen_title) +FROM movie +NATURAL JOIN movie_genres +NATURAL JOIN genres +GROUP BY gen_title; +ORDER BY mov_dt_rel desc; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/24. Write a query in SQL to find those lowest duration movies along with the year, director's name, actor's name and his or her role in that production.sql b/sql/SQLMovieDatabase/24. Write a query in SQL to find those lowest duration movies along with the year, director's name, actor's name and his or her role in that production.sql new file mode 100644 index 0000000..5e04f77 --- /dev/null +++ b/sql/SQLMovieDatabase/24. Write a query in SQL to find those lowest duration movies along with the year, director's name, actor's name and his or her role in that production.sql @@ -0,0 +1,10 @@ +/*24. Write a query in SQL to find those lowest duration movies along with the year, director's name, actor's name and his/her +role in that production.*/ +SELECT mov_title, mov_year, dir_fname, dir_lname, + act_fname, act_lname, role +FROM movie +NATURAL JOIN movie_direction +NATURAL JOIN movie_cast +NATURAL JOIN director +NATURAL JOIN actor +WHERE mov_time=(SELECT MIN(mov_time) FROM movie); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/25. Write a query in SQL to find the movie title, year, date of release, director and actor for those movies which reviewer is unknown.sql b/sql/SQLMovieDatabase/25. Write a query in SQL to find the movie title, year, date of release, director and actor for those movies which reviewer is unknown.sql new file mode 100644 index 0000000..d49cb71 --- /dev/null +++ b/sql/SQLMovieDatabase/25. Write a query in SQL to find the movie title, year, date of release, director and actor for those movies which reviewer is unknown.sql @@ -0,0 +1,14 @@ +/*25. Write a query in SQL to find the movie title, year, date of release, director and actor for those movies which reviewer + is unknown.*/ + +SELECT mov_title, mov_year, mov_dt_rel, dir_fname, dir_lname, + act_fname, act_lname + FROM movie a, movie_direction b, director c, + rating d, reviewer e, actor f, movie_cast g + WHERE a.mov_id=b.mov_id +AND b.dir_id=c.dir_id + AND a.mov_id=d.mov_id + AND d.rev_id=e.rev_id + AND a.mov_id=g.mov_id + AND g.act_id=f.act_id + AND e.rev_name IS NULL; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/26. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.sql b/sql/SQLMovieDatabase/26. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.sql new file mode 100644 index 0000000..508941d --- /dev/null +++ b/sql/SQLMovieDatabase/26. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.sql @@ -0,0 +1,11 @@ +/*26. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.*/ + SELECT mov_title + FROM movie + WHERE mov_id=( + SELECT mov_id + FROM movie_direction + WHERE dir_id=( + SELECT dir_id + FROM director + WHERE dir_fname='Woody' AND dir_lname='Allen' + )); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/27. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.sql b/sql/SQLMovieDatabase/27. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.sql new file mode 100644 index 0000000..76941f0 --- /dev/null +++ b/sql/SQLMovieDatabase/27. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.sql @@ -0,0 +1,8 @@ +/*27. Write a query in SQL to find the titles of all movies directed by the director whose first and last name are Woddy Allen.*/ +SELECT DISTINCT mov_year +FROM movie +WHERE mov_id IN ( +SELECT mov_id +FROM rating +WHERE rev_stars>3) +ORDER BY mov_year; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/28. Write a query in SQL to find the titles of all movies that have no ratings.sql b/sql/SQLMovieDatabase/28. Write a query in SQL to find the titles of all movies that have no ratings.sql new file mode 100644 index 0000000..529acc3 --- /dev/null +++ b/sql/SQLMovieDatabase/28. Write a query in SQL to find the titles of all movies that have no ratings.sql @@ -0,0 +1,8 @@ +/*28. Write a query in SQL to find the titles of all movies that have no ratings.*/ +SELECT DISTINCT mov_title +FROM movie +WHERE mov_id IN ( +SELECT mov_id +FROM movie +WHERE mov_id NOT IN ( +SELECT mov_id FROM Rating)); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/29. Write a query in SQL to find the names of all reviewers who have ratings with a NULL value.sql b/sql/SQLMovieDatabase/29. Write a query in SQL to find the names of all reviewers who have ratings with a NULL value.sql new file mode 100644 index 0000000..8e333fb --- /dev/null +++ b/sql/SQLMovieDatabase/29. Write a query in SQL to find the names of all reviewers who have ratings with a NULL value.sql @@ -0,0 +1,7 @@ +/*29. Write a query in SQL to find the names of all reviewers who have ratings with a NULL value.*/ +SELECT DISTINCT rev_name +FROM reviewer +WHERE rev_id IN ( +SELECT rev_id +FROM rating +WHERE rev_stars IS NULL); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/3. Write a query in SQL to find the movie which was released in the year 1999.sql b/sql/SQLMovieDatabase/3. Write a query in SQL to find the movie which was released in the year 1999.sql new file mode 100644 index 0000000..072da3a --- /dev/null +++ b/sql/SQLMovieDatabase/3. Write a query in SQL to find the movie which was released in the year 1999.sql @@ -0,0 +1,4 @@ +/*3. Write a query in SQL to find the movie which was released in the year 1999. */ + SELECT mov_title + FROM movie + WHERE mov_year=1999; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/30. Write a query in SQL to return the reviewer name, movie title, and stars for those movies which reviewed by a reviewer and must be rated.sql b/sql/SQLMovieDatabase/30. Write a query in SQL to return the reviewer name, movie title, and stars for those movies which reviewed by a reviewer and must be rated.sql new file mode 100644 index 0000000..321a0ec --- /dev/null +++ b/sql/SQLMovieDatabase/30. Write a query in SQL to return the reviewer name, movie title, and stars for those movies which reviewed by a reviewer and must be rated.sql @@ -0,0 +1,9 @@ +/*30. Write a query in SQL to return the reviewer name, movie title, and stars for those movies which reviewed by a reviewer + and must be rated. Sort the result by reviewer name, movie title, and number of stars. */ + SELECT rev_name, mov_title, rev_stars + FROM reviewer, rating, movie + WHERE reviewer.rev_id=rating.rev_id + AND movie.mov_id=rating.mov_id + AND reviewer.rev_name IS NOT NULL + AND rating.rev_stars IS NOT NULL + ORDER BY rev_name, mov_title, rev_stars; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/31. Write a query in SQL to find the reviewer's name and the title of the movie for those reviewers who rated more than one movies.sql b/sql/SQLMovieDatabase/31. Write a query in SQL to find the reviewer's name and the title of the movie for those reviewers who rated more than one movies.sql new file mode 100644 index 0000000..cc2a008 --- /dev/null +++ b/sql/SQLMovieDatabase/31. Write a query in SQL to find the reviewer's name and the title of the movie for those reviewers who rated more than one movies.sql @@ -0,0 +1,8 @@ +/*31. Write a query in SQL to find the reviewer's name and the title of the movie for those reviewers who rated more than + one movies. */ +SELECT rev_name, mov_title +FROM reviewer, movie, rating, rating r2 +WHERE rating.mov_id=movie.mov_id + AND reviewer.rev_id=rating.rev_ID + AND rating.rev_id = r2.rev_id +GROUP BY rev_name, mov_title HAVING count(*) > 1; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/32. Write a query in SQL to find the movie title, and the highest number of stars that movie received and arranged the result according to the group.sql b/sql/SQLMovieDatabase/32. Write a query in SQL to find the movie title, and the highest number of stars that movie received and arranged the result according to the group.sql new file mode 100644 index 0000000..f6efc14 --- /dev/null +++ b/sql/SQLMovieDatabase/32. Write a query in SQL to find the movie title, and the highest number of stars that movie received and arranged the result according to the group.sql @@ -0,0 +1,8 @@ +/*32. Write a query in SQL to find the movie title, and the highest number of stars that movie received and arranged the + result according to the group of a movie and the movie title appear alphabetically in ascending order. */ +SELECT mov_title, MAX(rev_stars) +FROM movie, rating +WHERE movie.mov_id=rating.mov_id +AND rating.rev_stars IS NOT NULL +GROUP BY mov_title +ORDER BY mov_title; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/33. Write a query in SQL to find the names of all reviewers who rated the movie American Beauty.sql b/sql/SQLMovieDatabase/33. Write a query in SQL to find the names of all reviewers who rated the movie American Beauty.sql new file mode 100644 index 0000000..3010b61 --- /dev/null +++ b/sql/SQLMovieDatabase/33. Write a query in SQL to find the names of all reviewers who rated the movie American Beauty.sql @@ -0,0 +1,6 @@ +/*33. Write a query in SQL to find the names of all reviewers who rated the movie American Beauty. */ +SELECT DISTINCT reviewer.rev_name +FROM reviewer, rating, movie +WHERE reviewer.rev_id = rating.rev_id +AND movie.mov_id = rating.mov_id +AND movie.mov_title = 'American Beauty'; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/34. Write a query in SQL to find the titles of all movies which have been reviewed by anybody except by Paul Monks.sql b/sql/SQLMovieDatabase/34. Write a query in SQL to find the titles of all movies which have been reviewed by anybody except by Paul Monks.sql new file mode 100644 index 0000000..5394175 --- /dev/null +++ b/sql/SQLMovieDatabase/34. Write a query in SQL to find the titles of all movies which have been reviewed by anybody except by Paul Monks.sql @@ -0,0 +1,10 @@ +/*34. Write a query in SQL to find the titles of all movies which have been reviewed by anybody except by Paul Monks. */ +SELECT movie.mov_title +FROM movie +WHERE movie.mov_id IN( +SELECT mov_id +FROM rating +WHERE rev_id NOT IN ( +SELECT rev_id +FROM reviewer +WHERE rev_name='Paul Monks')); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/35. Write a query in SQL to return the reviewer name, movie title, and number of stars for those movies which rating is the lowest one.sql b/sql/SQLMovieDatabase/35. Write a query in SQL to return the reviewer name, movie title, and number of stars for those movies which rating is the lowest one.sql new file mode 100644 index 0000000..a37111e --- /dev/null +++ b/sql/SQLMovieDatabase/35. Write a query in SQL to return the reviewer name, movie title, and number of stars for those movies which rating is the lowest one.sql @@ -0,0 +1,10 @@ +/*35. Write a query in SQL to return the reviewer name, movie title, and number of stars for those movies which rating is + the lowest one. */ +SELECT reviewer.rev_name, movie.mov_title, rating.rev_stars +FROM reviewer, movie, rating +WHERE rating.rev_stars = ( +SELECT MIN(rating.rev_stars) +FROM rating +) +AND rating.rev_id = reviewer.rev_id +AND rating.mov_id = movie.mov_id; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/36. Write a query in SQL to find the titles of all movies directed by James Cameron.sql b/sql/SQLMovieDatabase/36. Write a query in SQL to find the titles of all movies directed by James Cameron.sql new file mode 100644 index 0000000..7b7b84b --- /dev/null +++ b/sql/SQLMovieDatabase/36. Write a query in SQL to find the titles of all movies directed by James Cameron.sql @@ -0,0 +1,11 @@ +/*36. Write a query in SQL to find the titles of all movies directed by James Cameron. */ +SELECT mov_title +FROM movie +WHERE mov_id IN ( +SELECT mov_id +FROM movie_direction +WHERE dir_id IN ( +SELECT dir_id +FROM director +WHERE dir_fname = 'James' AND dir_lname='Cameron' +)); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/37. Write a query in SQL to find all the years which produced a movie that received a rating of 3 or 4, and sort the result in increasing order.sql b/sql/SQLMovieDatabase/37. Write a query in SQL to find all the years which produced a movie that received a rating of 3 or 4, and sort the result in increasing order.sql new file mode 100644 index 0000000..3deabba --- /dev/null +++ b/sql/SQLMovieDatabase/37. Write a query in SQL to find all the years which produced a movie that received a rating of 3 or 4, and sort the result in increasing order.sql @@ -0,0 +1,7 @@ +/*37. Write a query in SQL to find all the years which produced a movie that received a rating of 3 or 4, and sort the +result in increasing order. */ +SELECT DISTINCT mov_year +FROM movie, rating +WHERE movie.mov_id = rating.mov_id +AND rev_stars IN (3, 4) +ORDER BY mov_year; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/38. Write a query in SQL to return the reviewer name, movie title, and stars in an order that reviewer name will come first, then by movie title, and lastly by number of stars.sql b/sql/SQLMovieDatabase/38. Write a query in SQL to return the reviewer name, movie title, and stars in an order that reviewer name will come first, then by movie title, and lastly by number of stars.sql new file mode 100644 index 0000000..0d5fd0b --- /dev/null +++ b/sql/SQLMovieDatabase/38. Write a query in SQL to return the reviewer name, movie title, and stars in an order that reviewer name will come first, then by movie title, and lastly by number of stars.sql @@ -0,0 +1,8 @@ +/*38. Write a query in SQL to return the reviewer name, movie title, and stars in an order that reviewer name will come + first, then by movie title, and lastly by number of stars. */ +SELECT rev_name, mov_title, rev_stars +FROM movie +INNER JOIN rating ON movie.mov_id = rating.mov_id +INNER JOIN reviewer ON reviewer.rev_id = rating.rev_id +WHERE rev_name IS NOT NULL +ORDER BY rev_name, mov_title, rev_stars; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/4. Write a query in SQL to find the movies which was released before 1998.sql b/sql/SQLMovieDatabase/4. Write a query in SQL to find the movies which was released before 1998.sql new file mode 100644 index 0000000..177ffef --- /dev/null +++ b/sql/SQLMovieDatabase/4. Write a query in SQL to find the movies which was released before 1998.sql @@ -0,0 +1,4 @@ +/*4. Write a query in SQL to find the movies which was released before 1998. */ +SELECT mov_title +FROM movie +WHERE mov_year<1998; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/40. Write a query in SQL to find the director's first and last name together with the title of the movie(s) they directed and received the rating.sql b/sql/SQLMovieDatabase/40. Write a query in SQL to find the director's first and last name together with the title of the movie(s) they directed and received the rating.sql new file mode 100644 index 0000000..550bd13 --- /dev/null +++ b/sql/SQLMovieDatabase/40. Write a query in SQL to find the director's first and last name together with the title of the movie(s) they directed and received the rating.sql @@ -0,0 +1,8 @@ +/*40. Write a query in SQL to find the director's first and last name together with the title of the movie(s) they directed +and received the rating. */ +SELECT mov_title, dir_fname,dir_lname, rev_stars +FROM Movie +JOIN movie_direction USING(mov_id) +join director using (dir_id) +left join rating using(mov_id) +where rev_stars is not null; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/41. Write a query in SQL to find the name of those movies where one or more actors acted in two or more movies.sql b/sql/SQLMovieDatabase/41. Write a query in SQL to find the name of those movies where one or more actors acted in two or more movies.sql new file mode 100644 index 0000000..0b9a072 --- /dev/null +++ b/sql/SQLMovieDatabase/41. Write a query in SQL to find the name of those movies where one or more actors acted in two or more movies.sql @@ -0,0 +1,13 @@ +/*41. Write a query in SQL to find the name of those movies where one or more actors acted in two or more movies. */ + SELECT mov_title + FROM movie + WHERE mov_id IN ( + SELECT mov_id + FROM movie_cast + WHERE act_id IN ( + SELECT act_id + FROM actor + WHERE act_id IN ( + SELECT act_id + FROM movie_cast GROUP BY act_id + HAVING COUNT(act_id)>1))); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/42. Write a query in SQL to find the movie title, actor first and last name, and the role for those movies where one or more actors acted in two or more movies.sql b/sql/SQLMovieDatabase/42. Write a query in SQL to find the movie title, actor first and last name, and the role for those movies where one or more actors acted in two or more movies.sql new file mode 100644 index 0000000..41da710 --- /dev/null +++ b/sql/SQLMovieDatabase/42. Write a query in SQL to find the movie title, actor first and last name, and the role for those movies where one or more actors acted in two or more movies.sql @@ -0,0 +1,12 @@ +/*42. Write a query in SQL to find the movie title, actor first and last name, and the role for those movies where one or +more actors acted in two or more movies. */ +SELECT mov_title, act_fname, act_lname, role +FROM movie +JOIN movie_cast + ON movie_cast.mov_id=movie.mov_id +JOIN actor + ON movie_cast.act_id=actor.act_id +WHERE actor.act_id IN ( +SELECT act_id +FROM movie_cast +GROUP BY act_id HAVING COUNT(*)>=2); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/43. Write a query in SQL to find the first and last name of a director and the movie he or she directed, and the actress appeared which first name was Claire.sql b/sql/SQLMovieDatabase/43. Write a query in SQL to find the first and last name of a director and the movie he or she directed, and the actress appeared which first name was Claire.sql new file mode 100644 index 0000000..3136cce --- /dev/null +++ b/sql/SQLMovieDatabase/43. Write a query in SQL to find the first and last name of a director and the movie he or she directed, and the actress appeared which first name was Claire.sql @@ -0,0 +1,14 @@ +/*43. Write a query in SQL to find the first and last name of a director and the movie he or she directed, and the actress + appeared which first name was Claire and last name was Danes along with her role in that movie. */ +SELECT dir_fname, dir_lname, mov_title, act_fname, act_lname, role +FROM actor +JOIN movie_cast + ON actor.act_id=movie_cast.act_id +JOIN movie_direction + ON movie_cast.mov_id=movie_direction.mov_id +JOIN director + ON movie_direction.dir_id=director.dir_id +JOIN movie + ON movie.mov_id=movie_direction.mov_id +WHERE act_fname='Claire' + AND act_lname='Danes'; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/44. Write a query in SQL to find the first and last name of an actor with their role in the movie which was also directed by themselve.sql b/sql/SQLMovieDatabase/44. Write a query in SQL to find the first and last name of an actor with their role in the movie which was also directed by themselve.sql new file mode 100644 index 0000000..1ac5e81 --- /dev/null +++ b/sql/SQLMovieDatabase/44. Write a query in SQL to find the first and last name of an actor with their role in the movie which was also directed by themselve.sql @@ -0,0 +1,14 @@ +/*44. Write a query in SQL to find the first and last name of an actor with their role in the movie which was also directed + by themselve. */ +SELECT act_fname, act_lname, mov_title, role +FROM actor +JOIN movie_cast + ON actor.act_id=movie_cast.act_id +JOIN movie_direction + ON movie_cast.mov_id=movie_direction.mov_id +JOIN director + ON movie_direction.dir_id=director.dir_id +JOIN movie + ON movie.mov_id=movie_direction.mov_id +WHERE act_fname=dir_fname + AND act_lname=dir_lname; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/45. Write a query in SQL to find the cast list for the movie Chinatown.sql b/sql/SQLMovieDatabase/45. Write a query in SQL to find the cast list for the movie Chinatown.sql new file mode 100644 index 0000000..7b29fb1 --- /dev/null +++ b/sql/SQLMovieDatabase/45. Write a query in SQL to find the cast list for the movie Chinatown.sql @@ -0,0 +1,10 @@ +/*45. Write a query in SQL to find the cast list for the movie Chinatown. */ +SELECT a.act_fname, a.act_lname +FROM +movie_cast c +JOIN actor a ON +c.act_id = a.act_id +Where mov_id = ( +SELECT mov_id +FROM movie +Where mov_title = 'Chinatown'); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/46. Write a query in SQL to find the movie in which the actor appeared whose first and last name are 'Harrison' and 'Ford'.sql b/sql/SQLMovieDatabase/46. Write a query in SQL to find the movie in which the actor appeared whose first and last name are 'Harrison' and 'Ford'.sql new file mode 100644 index 0000000..1a4d166 --- /dev/null +++ b/sql/SQLMovieDatabase/46. Write a query in SQL to find the movie in which the actor appeared whose first and last name are 'Harrison' and 'Ford'.sql @@ -0,0 +1,10 @@ +/*46. Write a query in SQL to find the movie in which the actor appeared whose first and last name are 'Harrison' and 'Ford'. */ + SELECT m.mov_title + FROM movie m + JOIN movie_cast c + ON m.mov_id = c.mov_id + WHERE c.act_id IN ( + Select act_id + FROM actor + WHERE act_fname='Harrison' + AND act_lname='Ford'); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/47. Write a query in SQL to find the highest-rated movie, and report its title, year, rating, and releasing country.sql b/sql/SQLMovieDatabase/47. Write a query in SQL to find the highest-rated movie, and report its title, year, rating, and releasing country.sql new file mode 100644 index 0000000..70c712f --- /dev/null +++ b/sql/SQLMovieDatabase/47. Write a query in SQL to find the highest-rated movie, and report its title, year, rating, and releasing country.sql @@ -0,0 +1,8 @@ +/*47. Write a query in SQL to find the highest-rated movie, and report its title, year, rating, and releasing country. */ +SELECT mov_title, mov_year, rev_stars, mov_rel_country +FROM movie +NATURAL JOIN rating +WHERE rev_stars = ( +SELECT MAX(rev_stars) +FROM rating +); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/48. Write a query in SQL to find the highest-rated Mystery movie, and report the title, year, and rating.sql b/sql/SQLMovieDatabase/48. Write a query in SQL to find the highest-rated Mystery movie, and report the title, year, and rating.sql new file mode 100644 index 0000000..fdddeba --- /dev/null +++ b/sql/SQLMovieDatabase/48. Write a query in SQL to find the highest-rated Mystery movie, and report the title, year, and rating.sql @@ -0,0 +1,12 @@ +/*48. Write a query in SQL to find the highest-rated Mystery movie, and report the title, year, and rating. */ +SELECT mov_title, mov_year, rev_stars +FROM movie +NATURAL JOIN movie_genres +NATURAL JOIN genres +NATURAL JOIN rating +WHERE gen_title = 'Mystery' AND rev_stars >= ALL ( +SELECT rev_stars +FROM rating +NATURAL JOIN movie_genres +NATURAL JOIN genres +WHERE gen_title = 'Mystery'); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/49. Write a query in SQL to generate a report which shows the year when most of the Mystery movies produces, and number of movies and their average rating.sql b/sql/SQLMovieDatabase/49. Write a query in SQL to generate a report which shows the year when most of the Mystery movies produces, and number of movies and their average rating.sql new file mode 100644 index 0000000..1b8c009 --- /dev/null +++ b/sql/SQLMovieDatabase/49. Write a query in SQL to generate a report which shows the year when most of the Mystery movies produces, and number of movies and their average rating.sql @@ -0,0 +1,9 @@ +/*49. Write a query in SQL to generate a report which shows the year when most of the Mystery movies produces, and number +of movies and their average rating. */ +SELECT mov_year,gen_title,count(gen_title), avg(rev_stars) +FROM movie +NATURAL JOIN movie_genres +NATURAL JOIN genres +NATURAL JOIN rating +WHERE gen_title='Mystery' +GROUP BY mov_year,gen_title ; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/5. Write a query in SQL to return the name of all reviewers and name of movies together in a single list, alphabetically.sql b/sql/SQLMovieDatabase/5. Write a query in SQL to return the name of all reviewers and name of movies together in a single list, alphabetically.sql new file mode 100644 index 0000000..6fea7c0 --- /dev/null +++ b/sql/SQLMovieDatabase/5. Write a query in SQL to return the name of all reviewers and name of movies together in a single list, alphabetically.sql @@ -0,0 +1,6 @@ +/*5. Write a query in SQL to return the name of all reviewers and name of movies together in a single list, alphabetically. */ + SELECT reviewer.rev_name + FROM reviewer + UNION + SELECT movie.mov_title + FROM movie; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/6. Write a query in SQL to find the name of all reviewers who have rated 7 or more stars to their rating.sql b/sql/SQLMovieDatabase/6. Write a query in SQL to find the name of all reviewers who have rated 7 or more stars to their rating.sql new file mode 100644 index 0000000..b9e7a4b --- /dev/null +++ b/sql/SQLMovieDatabase/6. Write a query in SQL to find the name of all reviewers who have rated 7 or more stars to their rating.sql @@ -0,0 +1,6 @@ +/*6. Write a query in SQL to find the name of all reviewers who have rated 7 or more stars to their rating. */ +SELECT reviewer.rev_name +FROM reviewer, rating +WHERE rating.rev_id = reviewer.rev_id +AND rating.rev_stars>=7 +AND reviewer.rev_name IS NOT NULL; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/7. Write a query in SQL to find the titles of all movies that have no ratings.sql b/sql/SQLMovieDatabase/7. Write a query in SQL to find the titles of all movies that have no ratings.sql new file mode 100644 index 0000000..5a4cfc9 --- /dev/null +++ b/sql/SQLMovieDatabase/7. Write a query in SQL to find the titles of all movies that have no ratings.sql @@ -0,0 +1,7 @@ +/*7. Write a query in SQL to find the titles of all movies that have no ratings. */ + SELECT mov_title + FROM movie + WHERE mov_id NOT IN ( + SELECT mov_id + FROM rating + ); \ No newline at end of file diff --git a/sql/SQLMovieDatabase/8. Write a query in SQL to find the name of all reviewers who have rated their ratings with a NULL value.sql b/sql/SQLMovieDatabase/8. Write a query in SQL to find the name of all reviewers who have rated their ratings with a NULL value.sql new file mode 100644 index 0000000..3518fcc --- /dev/null +++ b/sql/SQLMovieDatabase/8. Write a query in SQL to find the name of all reviewers who have rated their ratings with a NULL value.sql @@ -0,0 +1,5 @@ +/*8. Write a query in SQL to find the name of all reviewers who have rated their ratings with a NULL value. */ + SELECT rev_name + FROM reviewer + INNER JOIN rating USING(rev_id) + WHERE rev_stars IS NULL; \ No newline at end of file diff --git a/sql/SQLMovieDatabase/9. Write a query in SQL to find the titles of the movies with ID 905, 907, 917.sql b/sql/SQLMovieDatabase/9. Write a query in SQL to find the titles of the movies with ID 905, 907, 917.sql new file mode 100644 index 0000000..b35a956 --- /dev/null +++ b/sql/SQLMovieDatabase/9. Write a query in SQL to find the titles of the movies with ID 905, 907, 917.sql @@ -0,0 +1,4 @@ +/*9. Write a query in SQL to find the titles of the movies with ID 905, 907, 917. */ +SELECT mov_title +FROM movie +WHERE mov_id in (905, 907, 917); \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/1. Write a query in SQL to display the full name (first and last name), and salary for those employees who earn below 6000.sql b/sql/SortingFilteringHRDatabase/1. Write a query in SQL to display the full name (first and last name), and salary for those employees who earn below 6000.sql new file mode 100644 index 0000000..c3dfafa --- /dev/null +++ b/sql/SortingFilteringHRDatabase/1. Write a query in SQL to display the full name (first and last name), and salary for those employees who earn below 6000.sql @@ -0,0 +1,4 @@ +/*1. Write a query in SQL to display the full name (first and last name), and salary for those employees who earn below 6000. */ +SELECT first_name ||' '||last_name AS Full_Name, salary + FROM employees + WHERE salary < 6000; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/10. Write a query in SQL to display the first and last name, and salary for those employees whose first name is ending with the letter m.sql b/sql/SortingFilteringHRDatabase/10. Write a query in SQL to display the first and last name, and salary for those employees whose first name is ending with the letter m.sql new file mode 100644 index 0000000..242aac8 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/10. Write a query in SQL to display the first and last name, and salary for those employees whose first name is ending with the letter m.sql @@ -0,0 +1,5 @@ +/*10. Write a query in SQL to display the first and last name, and salary for those employees whose first name is ending with + the letter m.*/ +SELECT first_name, last_name, salary + FROM employees + WHERE first_name LIKE '%m'; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/11. Write a query in SQL to display the full name (first and last) name, and salary, for all employees whose salary is out of the range 7000 and 15000.sql b/sql/SortingFilteringHRDatabase/11. Write a query in SQL to display the full name (first and last) name, and salary, for all employees whose salary is out of the range 7000 and 15000.sql new file mode 100644 index 0000000..c93a04a --- /dev/null +++ b/sql/SortingFilteringHRDatabase/11. Write a query in SQL to display the full name (first and last) name, and salary, for all employees whose salary is out of the range 7000 and 15000.sql @@ -0,0 +1,6 @@ +/*11. Write a query in SQL to display the full name (first and last) name, and salary, for all employees whose salary is out of +the range 7000 and 15000 and make the result set in ascending order by the full name.*/ +SELECT first_name || ' ' || last_name as Name, salary + FROM employees + WHERE salary NOT BETWEEN 7000 AND 15000 + ORDER BY first_name || ' ' || last_name; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/13. Write a query in SQL to display the the full name (first and last name), and department number for those employees who works either in department 70 or 90.sql b/sql/SortingFilteringHRDatabase/13. Write a query in SQL to display the the full name (first and last name), and department number for those employees who works either in department 70 or 90.sql new file mode 100644 index 0000000..46c3fd2 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/13. Write a query in SQL to display the the full name (first and last name), and department number for those employees who works either in department 70 or 90.sql @@ -0,0 +1,6 @@ +/*13. Write a query in SQL to display the the full name (first and last name), and department number for those employees who +works either in department 70 or 90.*/ +SELECT first_name ||' '|| last_name AS Full_Name, department_id + FROM employees + WHERE department_id = 70 + OR department_id = 90; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/14. Write a query in SQL to display the full name (first and last name), salary, and manager number for those employees.sql b/sql/SortingFilteringHRDatabase/14. Write a query in SQL to display the full name (first and last name), salary, and manager number for those employees.sql new file mode 100644 index 0000000..044ebf0 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/14. Write a query in SQL to display the full name (first and last name), salary, and manager number for those employees.sql @@ -0,0 +1,5 @@ +/*14. Write a query in SQL to display the full name (first and last name), salary, and manager number for those employees who is +working under a manager.*/ +SELECT first_name ||' '||last_name AS Full_Name, salary, manager_id + FROM employees + WHERE manager_id IS NOT NULL; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/15. Write a query in SQL to display all the information from Employees table for those employees who was hired before June 21st, 1987.sql b/sql/SortingFilteringHRDatabase/15. Write a query in SQL to display all the information from Employees table for those employees who was hired before June 21st, 1987.sql new file mode 100644 index 0000000..cfd1324 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/15. Write a query in SQL to display all the information from Employees table for those employees who was hired before June 21st, 1987.sql @@ -0,0 +1,5 @@ +/*15. Write a query in SQL to display all the information from Employees table for +those employees who was hired before June 21st, 1987.*/ +SELECT * + FROM employees + WHERE hire_date < '1987-06-21'; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/16. Write a query in SQL to display the first and last name, email, salary and manager ID, for those employees whose managers are hold the ID 120, 103 or 145.sql b/sql/SortingFilteringHRDatabase/16. Write a query in SQL to display the first and last name, email, salary and manager ID, for those employees whose managers are hold the ID 120, 103 or 145.sql new file mode 100644 index 0000000..35a42a2 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/16. Write a query in SQL to display the first and last name, email, salary and manager ID, for those employees whose managers are hold the ID 120, 103 or 145.sql @@ -0,0 +1,6 @@ +/*16. Write a query in SQL to display the first and last name, email, salary and manager ID, for those employees whose + managers are hold the ID 120, 103 or 145.*/ + SELECT first_name, last_name, email, + salary, manager_id + FROM employees + WHERE manager_id IN (120 , 103 , 145); \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/18. Write a query in SQL to display the full name (first name and last name), hire date, commission percentage.sql b/sql/SortingFilteringHRDatabase/18. Write a query in SQL to display the full name (first name and last name), hire date, commission percentage.sql new file mode 100644 index 0000000..646cbe5 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/18. Write a query in SQL to display the full name (first name and last name), hire date, commission percentage.sql @@ -0,0 +1,9 @@ +/*18. Write a query in SQL to display the full name (first name and last name), hire date, commission percentage, and +telephone separated by '-', and salary for those employees who earn the salary above 11000 or the seventh digit in their + phone number equals 3 and make the result set in a descending order by the first name. */ + SELECT first_name ||' '||last_name AS Full_Name, hire_date , + commission_pct, email ||' - '||phone_number AS Contact_Details, salary + FROM employees + WHERE salary > 11000 + OR phone_number LIKE '______3%' + ORDER BY first_name DESC; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/19. Write a query in SQL to display the first and last name, and department number for those employees who holds a letter.sql b/sql/SortingFilteringHRDatabase/19. Write a query in SQL to display the first and last name, and department number for those employees who holds a letter.sql new file mode 100644 index 0000000..653b7fc --- /dev/null +++ b/sql/SortingFilteringHRDatabase/19. Write a query in SQL to display the first and last name, and department number for those employees who holds a letter.sql @@ -0,0 +1,5 @@ +/*19. Write a query in SQL to display the first and last name, and department number for those employees + who holds a letter s as a 3rd character in their first name.*/ + SELECT first_name,last_name, department_id + FROM employees + WHERE first_name LIKE '__s%'; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/2. Write a query in SQL to display the first and last_name, department number and salary for those employees who earn more than 8000.sql b/sql/SortingFilteringHRDatabase/2. Write a query in SQL to display the first and last_name, department number and salary for those employees who earn more than 8000.sql new file mode 100644 index 0000000..13cf58e --- /dev/null +++ b/sql/SortingFilteringHRDatabase/2. Write a query in SQL to display the first and last_name, department number and salary for those employees who earn more than 8000.sql @@ -0,0 +1,5 @@ +/*2. Write a query in SQL to display the first and last_name, department number and + salary for those employees who earn more than 8000. */ + SELECT first_name,last_name, department_id, salary + FROM employees + WHERE salary > 8000; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/20. Write a query in SQL to display the employee ID, first name, job id, and department number for those employees who is working except the departments 50,30 and 80.sql b/sql/SortingFilteringHRDatabase/20. Write a query in SQL to display the employee ID, first name, job id, and department number for those employees who is working except the departments 50,30 and 80.sql new file mode 100644 index 0000000..84ea9d3 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/20. Write a query in SQL to display the employee ID, first name, job id, and department number for those employees who is working except the departments 50,30 and 80.sql @@ -0,0 +1,5 @@ +/*20. Write a query in SQL to display the employee ID, first name, job id, and department +number for those employees who is working except the departments 50,30 and 80.*/ +SELECT employee_id, first_name, job_id, department_id + FROM employees + WHERE department_id NOT IN (50, 30, 80); \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/21. Write a query in SQL to display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90.sql b/sql/SortingFilteringHRDatabase/21. Write a query in SQL to display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90.sql new file mode 100644 index 0000000..b1f3dfe --- /dev/null +++ b/sql/SortingFilteringHRDatabase/21. Write a query in SQL to display the employee Id, first name, job id, and department number for those employees whose department number equals 30, 40 or 90.sql @@ -0,0 +1,5 @@ +/*21. Write a query in SQL to display the employee Id, first name, job id, and department number for +those employees whose department number equals 30, 40 or 90.*/ +SELECT employee_id, first_name, job_id, department_id + FROM employees + WHERE department_id IN (30 , 40 , 90); \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/22. Write a query in SQL to display the ID for those employees who did two or more jobs in the past.sql b/sql/SortingFilteringHRDatabase/22. Write a query in SQL to display the ID for those employees who did two or more jobs in the past.sql new file mode 100644 index 0000000..b29a29a --- /dev/null +++ b/sql/SortingFilteringHRDatabase/22. Write a query in SQL to display the ID for those employees who did two or more jobs in the past.sql @@ -0,0 +1,5 @@ +/*22. Write a query in SQL to display the ID for those employees who did two or more jobs in the past.*/ +SELECT employee_id + FROM job_history + GROUP BY employee_id + HAVING COUNT(*) >=2; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/23. Write a query in SQL to display job ID, number of employees, sum of salary, and difference between highest salary and lowest salary for a job.sql b/sql/SortingFilteringHRDatabase/23. Write a query in SQL to display job ID, number of employees, sum of salary, and difference between highest salary and lowest salary for a job.sql new file mode 100644 index 0000000..2bf5025 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/23. Write a query in SQL to display job ID, number of employees, sum of salary, and difference between highest salary and lowest salary for a job.sql @@ -0,0 +1,6 @@ +/*23. Write a query in SQL to display job ID, number of employees, sum of salary, + and difference between highest salary and lowest salary for a job.*/ + SELECT job_id, COUNT(*), SUM(salary), + MAX(salary)-MIN(salary) AS salary_difference + FROM employees + GROUP BY job_id; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/24. Write a query in SQL to display job ID for those jobs that were done by two or more for more than 300 days.sql b/sql/SortingFilteringHRDatabase/24. Write a query in SQL to display job ID for those jobs that were done by two or more for more than 300 days.sql new file mode 100644 index 0000000..2745007 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/24. Write a query in SQL to display job ID for those jobs that were done by two or more for more than 300 days.sql @@ -0,0 +1,6 @@ +/*24. Write a query in SQL to display job ID for those jobs that were done by two or more for more than 300 days.*/ +SELECT job_id + FROM job_history + WHERE end_date-start_date >300 + GROUP BY job_id + HAVING COUNT(*)>=2; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/25. Write a query in SQL to display the country ID and number of cities in that country we have.sql b/sql/SortingFilteringHRDatabase/25. Write a query in SQL to display the country ID and number of cities in that country we have.sql new file mode 100644 index 0000000..cd32b25 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/25. Write a query in SQL to display the country ID and number of cities in that country we have.sql @@ -0,0 +1,4 @@ +/*25. Write a query in SQL to display the country ID and number of cities in that country we have.*/ +SELECT country_id, COUNT(*) + FROM locations + GROUP BY country_id; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/26. Write a query in SQL to display the manager ID and number of employees managed by the manager.sql b/sql/SortingFilteringHRDatabase/26. Write a query in SQL to display the manager ID and number of employees managed by the manager.sql new file mode 100644 index 0000000..98f96e3 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/26. Write a query in SQL to display the manager ID and number of employees managed by the manager.sql @@ -0,0 +1,4 @@ +/*26. Write a query in SQL to display the manager ID and number of employees managed by the manager.*/ +SELECT manager_id, COUNT(*) +FROM employees + GROUP BY manager_id;; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/27. Write a query in SQL to display the details of jobs in descending sequence on job title.sql b/sql/SortingFilteringHRDatabase/27. Write a query in SQL to display the details of jobs in descending sequence on job title.sql new file mode 100644 index 0000000..96ca55b --- /dev/null +++ b/sql/SortingFilteringHRDatabase/27. Write a query in SQL to display the details of jobs in descending sequence on job title.sql @@ -0,0 +1,4 @@ +/*27. Write a query in SQL to display the details of jobs in descending sequence on job title.*/ +SELECT * + FROM jobs + ORDER BY job_title; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/28. Write a query in SQL to display the first and last name and date of joining of the employees.sql b/sql/SortingFilteringHRDatabase/28. Write a query in SQL to display the first and last name and date of joining of the employees.sql new file mode 100644 index 0000000..01523f8 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/28. Write a query in SQL to display the first and last name and date of joining of the employees.sql @@ -0,0 +1,5 @@ +/*28. Write a query in SQL to display the first and last name and date of joining of +the employees who is either Sales Representative or Sales Man.*/ +SELECT first_name, last_name, hire_date + FROM employees + WHERE job_id IN ('SA_REP', 'SA_MAN'); \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/29. Write a query in SQL to display the average salary of employees for each department who gets a commission percentage.sql b/sql/SortingFilteringHRDatabase/29. Write a query in SQL to display the average salary of employees for each department who gets a commission percentage.sql new file mode 100644 index 0000000..1a2fee0 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/29. Write a query in SQL to display the average salary of employees for each department who gets a commission percentage.sql @@ -0,0 +1,5 @@ +/*29. Write a query in SQL to display the average salary of employees for each department who gets a commission percentage.*/ +SELECT department_id, AVG(salary) + FROM employees + WHERE commission_pct IS NOT NULL + GROUP BY department_id; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/3. Write a query in SQL to display the first and last name, and department number for all employees whose last name is McEwen.sql b/sql/SortingFilteringHRDatabase/3. Write a query in SQL to display the first and last name, and department number for all employees whose last name is McEwen.sql new file mode 100644 index 0000000..8188075 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/3. Write a query in SQL to display the first and last name, and department number for all employees whose last name is McEwen.sql @@ -0,0 +1,5 @@ +/*3. Write a query in SQL to display the first and last name, and department +number for all employees whose last name is “McEwen”. */ +SELECT first_name, last_name, department_id + FROM employees + WHERE last_name = 'McEwen'; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/30. Write a query in SQL to display those departments where any manager is managing 4 or more employees.sql b/sql/SortingFilteringHRDatabase/30. Write a query in SQL to display those departments where any manager is managing 4 or more employees.sql new file mode 100644 index 0000000..0823cdd --- /dev/null +++ b/sql/SortingFilteringHRDatabase/30. Write a query in SQL to display those departments where any manager is managing 4 or more employees.sql @@ -0,0 +1,5 @@ +/*30. Write a query in SQL to display those departments where any manager is managing 4 or more employees.*/ +SELECT DISTINCT department_id + FROM employees + GROUP BY department_id, manager_id + HAVING COUNT(employee_id) >=4; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/31. Write a query in SQL to display those departments where more than ten employees work.sql b/sql/SortingFilteringHRDatabase/31. Write a query in SQL to display those departments where more than ten employees work.sql new file mode 100644 index 0000000..41206bb --- /dev/null +++ b/sql/SortingFilteringHRDatabase/31. Write a query in SQL to display those departments where more than ten employees work.sql @@ -0,0 +1,6 @@ +/*31. Write a query in SQL to display those departments where more than ten employees work who got a commission percentage.*/ +SELECT department_id + FROM employees + WHERE commission_pct IS NOT NULL + GROUP BY department_id + HAVING COUNT(commission_pct)>10; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/32. Write a query in SQL to display the employee ID and the date on which he ended his previous job.sql b/sql/SortingFilteringHRDatabase/32. Write a query in SQL to display the employee ID and the date on which he ended his previous job.sql new file mode 100644 index 0000000..bf74738 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/32. Write a query in SQL to display the employee ID and the date on which he ended his previous job.sql @@ -0,0 +1,4 @@ +/*32. Write a query in SQL to display the employee ID and the date on which he ended his previous job.*/ + SELECT employee_id, MAX(end_date) + FROM job_history + GROUP BY employee_id; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/34. Write a query in SQL to display the job ID for those jobs which average salary is above 8000.sql b/sql/SortingFilteringHRDatabase/34. Write a query in SQL to display the job ID for those jobs which average salary is above 8000.sql new file mode 100644 index 0000000..30520a3 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/34. Write a query in SQL to display the job ID for those jobs which average salary is above 8000.sql @@ -0,0 +1,5 @@ +/*34. Write a query in SQL to display the job ID for those jobs which average salary is above 8000.*/ +SELECT job_id, AVG(salary) + FROM employees + GROUP BY job_id + HAVING AVG(salary)>8000; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/35. Write a query in SQL to display job Title, the difference between minimum and maximum salaries for those jobs which max salary within the range 12000 to 18000.sql b/sql/SortingFilteringHRDatabase/35. Write a query in SQL to display job Title, the difference between minimum and maximum salaries for those jobs which max salary within the range 12000 to 18000.sql new file mode 100644 index 0000000..09f1641 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/35. Write a query in SQL to display job Title, the difference between minimum and maximum salaries for those jobs which max salary within the range 12000 to 18000.sql @@ -0,0 +1,5 @@ +/*35. Write a query in SQL to display job Title, the difference between minimum and +maximum salaries for those jobs which max salary within the range 12000 to 18000.*/ + SELECT job_title, max_salary-min_salary AS salary_differences + FROM jobs + WHERE max_salary BETWEEN 12000 AND 18000; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/36. Write a query in SQL to display all those employees whose first name or last name starts with the letter D.sql b/sql/SortingFilteringHRDatabase/36. Write a query in SQL to display all those employees whose first name or last name starts with the letter D.sql new file mode 100644 index 0000000..4a85a1a --- /dev/null +++ b/sql/SortingFilteringHRDatabase/36. Write a query in SQL to display all those employees whose first name or last name starts with the letter D.sql @@ -0,0 +1,5 @@ +/*36. Write a query in SQL to display all those employees whose first name or last name starts with the letter D.*/ +SELECT first_name, last_name + FROM employees + WHERE first_name LIKE 'D%' + OR last_name LIKE 'D%'; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/37. Write a query in SQL to display the details of jobs which minimum salary is greater than 9000.sql b/sql/SortingFilteringHRDatabase/37. Write a query in SQL to display the details of jobs which minimum salary is greater than 9000.sql new file mode 100644 index 0000000..f35b7b2 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/37. Write a query in SQL to display the details of jobs which minimum salary is greater than 9000.sql @@ -0,0 +1,4 @@ +/*37. Write a query in SQL to display the details of jobs which minimum salary is greater than 9000.*/ +SELECT * + FROM jobs + WHERE min_salary > 9000; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/38. Write a query in SQL to display those employees who joined after 7th September, 1987.sql b/sql/SortingFilteringHRDatabase/38. Write a query in SQL to display those employees who joined after 7th September, 1987.sql new file mode 100644 index 0000000..78e719e --- /dev/null +++ b/sql/SortingFilteringHRDatabase/38. Write a query in SQL to display those employees who joined after 7th September, 1987.sql @@ -0,0 +1,4 @@ +/*38. Write a query in SQL to display those employees who joined after 7th September, 1987.*/ +SELECT * + FROM employees + WHERE hire_date > '1987-09-07'; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/4. Write a query in SQL to display all the information for all employees without any department number.sql b/sql/SortingFilteringHRDatabase/4. Write a query in SQL to display all the information for all employees without any department number.sql new file mode 100644 index 0000000..8571b49 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/4. Write a query in SQL to display all the information for all employees without any department number.sql @@ -0,0 +1,4 @@ +/*4. Write a query in SQL to display all the information for all employees without any department number. */ +SELECT * + FROM employees + WHERE department_id IS NULL; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/5. Write a query in SQL to display all the information about the department Marketing.sql b/sql/SortingFilteringHRDatabase/5. Write a query in SQL to display all the information about the department Marketing.sql new file mode 100644 index 0000000..6de4257 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/5. Write a query in SQL to display all the information about the department Marketing.sql @@ -0,0 +1,3 @@ +SELECT * + FROM departments + WHERE department_name = 'Marketing'; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/6. Write a query in SQL to display the full name (first and last), hire date, salary, and department number for those employees.sql b/sql/SortingFilteringHRDatabase/6. Write a query in SQL to display the full name (first and last), hire date, salary, and department number for those employees.sql new file mode 100644 index 0000000..7d4ceb2 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/6. Write a query in SQL to display the full name (first and last), hire date, salary, and department number for those employees.sql @@ -0,0 +1,7 @@ +/*6. Write a query in SQL to display the full name (first and last), hire date, salary, and department number for those +employees whose last name does not containing the letter M and make the result set in ascending order by department number.*/ +SELECT first_name || ' ' || last_name as Full_Name, hire_date, + salary, department_id + FROM employees + WHERE first_name NOT LIKE '%M%' + ORDER BY department_id; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/7. Write a query in SQL to display all the information of employees whose salary is in the range of 8000 and 12000 and commission is not null.sql b/sql/SortingFilteringHRDatabase/7. Write a query in SQL to display all the information of employees whose salary is in the range of 8000 and 12000 and commission is not null.sql new file mode 100644 index 0000000..ba3f0b6 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/7. Write a query in SQL to display all the information of employees whose salary is in the range of 8000 and 12000 and commission is not null.sql @@ -0,0 +1,8 @@ +/*7. Write a query in SQL to display all the information of employees whose salary is in the range of 8000 and 12000 and +commission is not null or department number is except the number 40, 120 and 70 and they have been hired before June 5th, 1987.*/ +SELECT * + FROM employees + WHERE salary BETWEEN 8000 AND 12000 + AND commission_pct IS NOT NULL + OR department_id NOT IN (40 , 120 , 70) + AND hire_date < '1987-06-05' \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/8. Write a query in SQL to display the full name (first and last name), and salary for all employees who does not earn any commission.sql b/sql/SortingFilteringHRDatabase/8. Write a query in SQL to display the full name (first and last name), and salary for all employees who does not earn any commission.sql new file mode 100644 index 0000000..ce40f86 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/8. Write a query in SQL to display the full name (first and last name), and salary for all employees who does not earn any commission.sql @@ -0,0 +1,5 @@ +/*8. Write a query in SQL to display the full name (first and last name), and salary for all employees who does not earn + any commission.*/ +SELECT first_name ||' '||last_name AS Full_Name, salary + FROM employees + WHERE commission_pct IS NULL; \ No newline at end of file diff --git a/sql/SortingFilteringHRDatabase/9. Write a query in SQL to display the full name (first and last), the phone number and email separated.sql b/sql/SortingFilteringHRDatabase/9. Write a query in SQL to display the full name (first and last), the phone number and email separated.sql new file mode 100644 index 0000000..c04d655 --- /dev/null +++ b/sql/SortingFilteringHRDatabase/9. Write a query in SQL to display the full name (first and last), the phone number and email separated.sql @@ -0,0 +1,8 @@ +/*9. Write a query in SQL to display the full name (first and last), the phone number and email separated by hyphen, and salary, + for those employees whose salary is within the range of 9000 and 17000. The column headings assign with Full_Name, + Contact_Details and Remuneration respectively.*/ +SELECT first_name ||' '||last_name AS Full_Name, + phone_number ||' - '|| email AS Contact_Details, + salary AS Remuneration + FROM employees + WHERE salary BETWEEN 9000 AND 17000; \ No newline at end of file diff --git a/sql/Subqueries/1. Write a query to display all the orders from the orders table issued by the salesman 'Paul Adam'.sql b/sql/Subqueries/1. Write a query to display all the orders from the orders table issued by the salesman 'Paul Adam'.sql new file mode 100644 index 0000000..e983dcc --- /dev/null +++ b/sql/Subqueries/1. Write a query to display all the orders from the orders table issued by the salesman 'Paul Adam'.sql @@ -0,0 +1,7 @@ +/*1. Write a query to display all the orders from the orders table issued by the salesman 'Paul Adam'.*/ +SELECT * +FROM orders +WHERE salesman_id = + (SELECT salesman_id + FROM salesman + WHERE name='Paul Adam'); \ No newline at end of file diff --git a/sql/Subqueries/10. Write a query to display all the customers with orders issued on date 17th August, 2012.sql b/sql/Subqueries/10. Write a query to display all the customers with orders issued on date 17th August, 2012.sql new file mode 100644 index 0000000..7a9e380 --- /dev/null +++ b/sql/Subqueries/10. Write a query to display all the customers with orders issued on date 17th August, 2012.sql @@ -0,0 +1,5 @@ +/*10. Write a query to display all the customers with orders issued on date 17th August, 2012.*/ +SELECT b.*, a.cust_name +FROM orders b, customer a +WHERE a.customer_id=b.customer_id +AND b.ord_date='2012-08-17'; \ No newline at end of file diff --git a/sql/Subqueries/11. Write a query to find the name and numbers of all salesmen who had more than one customer.sql b/sql/Subqueries/11. Write a query to find the name and numbers of all salesmen who had more than one customer.sql new file mode 100644 index 0000000..bfd7c2d --- /dev/null +++ b/sql/Subqueries/11. Write a query to find the name and numbers of all salesmen who had more than one customer.sql @@ -0,0 +1,6 @@ +SELECT salesman_id,name +FROM salesman a +WHERE 1 < + (SELECT COUNT(*) + FROM customer + WHERE salesman_id=a.salesman_id); \ No newline at end of file diff --git a/sql/Subqueries/12. Write a query to find all orders with order amounts which are above-average amounts for their customers.sql b/sql/Subqueries/12. Write a query to find all orders with order amounts which are above-average amounts for their customers.sql new file mode 100644 index 0000000..f176a41 --- /dev/null +++ b/sql/Subqueries/12. Write a query to find all orders with order amounts which are above-average amounts for their customers.sql @@ -0,0 +1,6 @@ +/*12. Write a query to find all orders with order amounts which are above-average amounts for their customers..*/ +SELECT * +FROM orders a +WHERE purch_amt > + (SELECT AVG(purch_amt) FROM orders b + WHERE b.customer_id = a.customer_id); \ No newline at end of file diff --git a/sql/Subqueries/13. Write a queries to find all orders with order amounts which are on or above-average amounts for their customers.sql b/sql/Subqueries/13. Write a queries to find all orders with order amounts which are on or above-average amounts for their customers.sql new file mode 100644 index 0000000..6ea3f7e --- /dev/null +++ b/sql/Subqueries/13. Write a queries to find all orders with order amounts which are on or above-average amounts for their customers.sql @@ -0,0 +1,6 @@ +/*13. Write a queries to find all orders with order amounts which are on or above-average amounts for their customers.*/ +SELECT * +FROM orders a +WHERE purch_amt > = + (SELECT AVG(purch_amt) FROM orders b + WHERE b.customer_id = a.customer_id); \ No newline at end of file diff --git a/sql/Subqueries/15. Write a query to extract the data from the customer table if and only if one or more of the customers in the customer table are located in London.sql b/sql/Subqueries/15. Write a query to extract the data from the customer table if and only if one or more of the customers in the customer table are located in London.sql new file mode 100644 index 0000000..53add9a --- /dev/null +++ b/sql/Subqueries/15. Write a query to extract the data from the customer table if and only if one or more of the customers in the customer table are located in London.sql @@ -0,0 +1,8 @@ +/*15. Write a query to extract the data from the customer table if and only if one or more of the customers in the customer +table are located in London.*/ +SELECT customer_id,cust_name, city +FROM customer +WHERE EXISTS + (SELECT * + FROM customer + WHERE city='London'); \ No newline at end of file diff --git a/sql/Subqueries/16. Write a query to find the salesmen who have multiple customers.sql b/sql/Subqueries/16. Write a query to find the salesmen who have multiple customers.sql new file mode 100644 index 0000000..2ab49e2 --- /dev/null +++ b/sql/Subqueries/16. Write a query to find the salesmen who have multiple customers.sql @@ -0,0 +1,11 @@ +/*16. Write a query to find the salesmen who have multiple customers.*/ +SELECT * +FROM salesman +WHERE salesman_id IN ( + SELECT DISTINCT salesman_id + FROM customer a + WHERE EXISTS ( + SELECT * + FROM customer b + WHERE b.salesman_id=a.salesman_id + AND b.cust_name<>a.cust_name)); \ No newline at end of file diff --git a/sql/Subqueries/17. Write a query to find all the salesmen who worked for only one customer.sql b/sql/Subqueries/17. Write a query to find all the salesmen who worked for only one customer.sql new file mode 100644 index 0000000..0669415 --- /dev/null +++ b/sql/Subqueries/17. Write a query to find all the salesmen who worked for only one customer.sql @@ -0,0 +1,10 @@ +/*17. Write a query to find all the salesmen who worked for only one customer.*/ +SELECT * +FROM salesman +WHERE salesman_id IN ( + SELECT DISTINCT salesman_id + FROM customer a + WHERE NOT EXISTS ( + SELECT * FROM customer b + WHERE a.salesman_id=b.salesman_id + AND a.cust_name<>b.cust_name)); \ No newline at end of file diff --git a/sql/Subqueries/18. Write a query that extract the rows of all salesmen who have customers with more than one orders.sql b/sql/Subqueries/18. Write a query that extract the rows of all salesmen who have customers with more than one orders.sql new file mode 100644 index 0000000..4df7916 --- /dev/null +++ b/sql/Subqueries/18. Write a query that extract the rows of all salesmen who have customers with more than one orders.sql @@ -0,0 +1,11 @@ +/*18. Write a query that extract the rows of all salesmen who have customers with more than one orders.*/ + SELECT * + FROM salesman a + WHERE EXISTS + (SELECT * FROM customer b + WHERE a.salesman_id=b.salesman_id + AND 1< + (SELECT COUNT (*) + FROM orders + WHERE orders.customer_id = + b.customer_id)); \ No newline at end of file diff --git a/sql/Subqueries/19. Write a query to find a salesman with customers located in their cities.sql b/sql/Subqueries/19. Write a query to find a salesman with customers located in their cities.sql new file mode 100644 index 0000000..d13f37a --- /dev/null +++ b/sql/Subqueries/19. Write a query to find a salesman with customers located in their cities.sql @@ -0,0 +1,6 @@ +/*19. Write a query to find a salesman with customers located in their cities.*/ +SELECT * +FROM salesman +WHERE city=ANY + (SELECT city + FROM customer); \ No newline at end of file diff --git a/sql/Subqueries/2. Write a query to display all the orders for the salesman who belongs to the city London.sql b/sql/Subqueries/2. Write a query to display all the orders for the salesman who belongs to the city London.sql new file mode 100644 index 0000000..5cd0bb3 --- /dev/null +++ b/sql/Subqueries/2. Write a query to display all the orders for the salesman who belongs to the city London.sql @@ -0,0 +1,7 @@ +/*2. Write a query to display all the orders for the salesman who belongs to the city London.*/ +SELECT * +FROM orders +WHERE salesman_id = + (SELECT salesman_id + FROM salesman + WHERE city='London'); \ No newline at end of file diff --git a/sql/Subqueries/20. Write a query to find all the salesmen for whom there are customers that follow them.sql b/sql/Subqueries/20. Write a query to find all the salesmen for whom there are customers that follow them.sql new file mode 100644 index 0000000..91b17ac --- /dev/null +++ b/sql/Subqueries/20. Write a query to find all the salesmen for whom there are customers that follow them.sql @@ -0,0 +1,6 @@ +/*20. Write a query to find all the salesmen for whom there are customers that follow them.*/ +SELECT * +FROM salesman +WHERE city IN + (SELECT city + FROM customer); \ No newline at end of file diff --git a/sql/Subqueries/21. Write a query to display the salesmen which name are alphabetically lower than the name of the customers.sql b/sql/Subqueries/21. Write a query to display the salesmen which name are alphabetically lower than the name of the customers.sql new file mode 100644 index 0000000..65466c9 --- /dev/null +++ b/sql/Subqueries/21. Write a query to display the salesmen which name are alphabetically lower than the name of the customers.sql @@ -0,0 +1,7 @@ +/*21. Write a query to display the salesmen which name are alphabetically lower than the name of the customers.*/ +SELECT * +FROM salesman a +WHERE EXISTS + (SELECT * + FROM CUSTOMER b + WHERE a.name < b.cust_name); \ No newline at end of file diff --git a/sql/Subqueries/22. Write a query to display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York.sql b/sql/Subqueries/22. Write a query to display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York.sql new file mode 100644 index 0000000..b2c40ef --- /dev/null +++ b/sql/Subqueries/22. Write a query to display the customers who have a greater gradation than any customer who belongs to the alphabetically lower than the city New York.sql @@ -0,0 +1,8 @@ +/*22. Write a query to display the customers who have a greater gradation than any customer who belongs to the alphabetically +lower than the city New York.*/ +SELECT * +FROM customer +WHERE grade > ANY + (SELECT grade + FROM CUSTOMER + WHERE city < 'New York'); \ No newline at end of file diff --git a/sql/Subqueries/23. Write a query to display all the orders that had amounts that were greater than at least one of the orders from October 9th 2012.sql b/sql/Subqueries/23. Write a query to display all the orders that had amounts that were greater than at least one of the orders from October 9th 2012.sql new file mode 100644 index 0000000..fb659fe --- /dev/null +++ b/sql/Subqueries/23. Write a query to display all the orders that had amounts that were greater than at least one of the orders from October 9th 2012.sql @@ -0,0 +1,8 @@ +/*23. Write a query to display all the orders that had amounts that were greater than at least one of the orders from + October 9th 2012.*/ +SELECT * +FROM Orders +WHERE purch_amt > ANY + (SELECT purch_amt + FROM orders + WHERE ord_date='2012/09/10'); \ No newline at end of file diff --git a/sql/Subqueries/24. Write a query to find all orders with an amount smaller than any amount for a customer in London.sql b/sql/Subqueries/24. Write a query to find all orders with an amount smaller than any amount for a customer in London.sql new file mode 100644 index 0000000..ba7c0b2 --- /dev/null +++ b/sql/Subqueries/24. Write a query to find all orders with an amount smaller than any amount for a customer in London.sql @@ -0,0 +1,8 @@ +/*24. Write a query to find all orders with an amount smaller than any amount for a customer in London.*/ + SELECT * + FROM orders + WHERE purch_amt < ANY + (SELECT purch_amt + FROM orders a, customer b + WHERE a.customer_id=b.customer_id + AND b.city='London'); \ No newline at end of file diff --git a/sql/Subqueries/25. Write a query to display all orders with an amount smaller than any amount for a customer in London.sql b/sql/Subqueries/25. Write a query to display all orders with an amount smaller than any amount for a customer in London.sql new file mode 100644 index 0000000..ceb1bd0 --- /dev/null +++ b/sql/Subqueries/25. Write a query to display all orders with an amount smaller than any amount for a customer in London.sql @@ -0,0 +1,8 @@ +/*25. Write a query to display all orders with an amount smaller than any amount for a customer in London.*/ +SELECT * +FROM orders +WHERE purch_amt < + (SELECT MAX (purch_amt) + FROM orders a, customer b + WHERE a.customer_id=b.customer_id + AND b.city='London'); \ No newline at end of file diff --git a/sql/Subqueries/26. Write a query to display only those customers whose grade are, in fact, higher than every customer in New York.sql b/sql/Subqueries/26. Write a query to display only those customers whose grade are, in fact, higher than every customer in New York.sql new file mode 100644 index 0000000..db0d5d9 --- /dev/null +++ b/sql/Subqueries/26. Write a query to display only those customers whose grade are, in fact, higher than every customer in New York.sql @@ -0,0 +1,7 @@ +/*26. Write a query to display only those customers whose grade are, in fact, higher than every customer in New York.*/ +SELECT * +FROM customer +WHERE grade > ALL + (SELECT grade + FROM customer + WHERE city='New York'); \ No newline at end of file diff --git a/sql/Subqueries/27. Write a query to find only those customers whose grade are, higher than every customer to the city New York.sql b/sql/Subqueries/27. Write a query to find only those customers whose grade are, higher than every customer to the city New York.sql new file mode 100644 index 0000000..56f58c0 --- /dev/null +++ b/sql/Subqueries/27. Write a query to find only those customers whose grade are, higher than every customer to the city New York.sql @@ -0,0 +1,8 @@ +/*27. Write a query to find only those customers whose grade are, higher than every customer to the city New York.*/ +SELECT * +FROM customer a +WHERE NOT EXISTS + (SELECT * + FROM customer b + WHERE a.grade<=b.grade + AND b.city='New York'); \ No newline at end of file diff --git a/sql/Subqueries/28.Write a query to get all the information for those customers whose grade is not as the grade of customer who belongs to the city London.sql b/sql/Subqueries/28.Write a query to get all the information for those customers whose grade is not as the grade of customer who belongs to the city London.sql new file mode 100644 index 0000000..c769255 --- /dev/null +++ b/sql/Subqueries/28.Write a query to get all the information for those customers whose grade is not as the grade of customer who belongs to the city London.sql @@ -0,0 +1,8 @@ +/*28.Write a query to get all the information for those customers whose grade is not as the grade of customer who belongs to +the city London.*/ +SELECT * +FROM customer +WHERE grade <> ALL + (SELECT grade + FROM customer + WHERE city='London'); \ No newline at end of file diff --git a/sql/Subqueries/29. Write a query to find all those customers whose grade are not as the grade, belongs to the city Paris.sql b/sql/Subqueries/29. Write a query to find all those customers whose grade are not as the grade, belongs to the city Paris.sql new file mode 100644 index 0000000..dd6afb3 --- /dev/null +++ b/sql/Subqueries/29. Write a query to find all those customers whose grade are not as the grade, belongs to the city Paris.sql @@ -0,0 +1,7 @@ +/*29. Write a query to find all those customers whose grade are not as the grade, belongs to the city Paris.*/ +SELECT * +FROM customer +WHERE grade NOT IN + (SELECT grade + FROM customer + WHERE city='Paris'); \ No newline at end of file diff --git a/sql/Subqueries/3. Write a query to find all the orders issued against the salesman who works for customer whose id is 3007.sql b/sql/Subqueries/3. Write a query to find all the orders issued against the salesman who works for customer whose id is 3007.sql new file mode 100644 index 0000000..bae15cd --- /dev/null +++ b/sql/Subqueries/3. Write a query to find all the orders issued against the salesman who works for customer whose id is 3007.sql @@ -0,0 +1,7 @@ +/*3. Write a query to find all the orders issued against the salesman who works for customer whose id is 3007.*/ +SELECT * +FROM orders +WHERE salesman_id = + (SELECT DISTINCT salesman_id + FROM orders + WHERE customer_id =3007); \ No newline at end of file diff --git a/sql/Subqueries/30. Write a query to find all those customers who hold a different grade than any customer of the city Dallas.sql b/sql/Subqueries/30. Write a query to find all those customers who hold a different grade than any customer of the city Dallas.sql new file mode 100644 index 0000000..752e5bd --- /dev/null +++ b/sql/Subqueries/30. Write a query to find all those customers who hold a different grade than any customer of the city Dallas.sql @@ -0,0 +1,7 @@ +/*30. Write a query to find all those customers who hold a different grade than any customer of the city Dallas.*/ + SELECT * + FROM customer + WHERE NOT grade = ANY + (SELECT grade + FROM customer + WHERE city='Dallas'); \ No newline at end of file diff --git a/sql/Subqueries/4. Write a query to display all the orders which values are greater than the average order value for 10th October 2012.sql b/sql/Subqueries/4. Write a query to display all the orders which values are greater than the average order value for 10th October 2012.sql new file mode 100644 index 0000000..e4bdf27 --- /dev/null +++ b/sql/Subqueries/4. Write a query to display all the orders which values are greater than the average order value for 10th October 2012.sql @@ -0,0 +1,7 @@ +/*4. Write a query to display all the orders which values are greater than the average order value for 10th October 2012.*/ +SELECT * +FROM orders +WHERE purch_amt > + (SELECT AVG(purch_amt) + FROM orders + WHERE ord_date ='10/10/2012'); \ No newline at end of file diff --git a/sql/Subqueries/5. Write a query to find all orders attributed to a salesman in New york.sql b/sql/Subqueries/5. Write a query to find all orders attributed to a salesman in New york.sql new file mode 100644 index 0000000..e447164 --- /dev/null +++ b/sql/Subqueries/5. Write a query to find all orders attributed to a salesman in New york.sql @@ -0,0 +1,7 @@ +/*5. Write a query to find all orders attributed to a salesman in New york.*/ +SELECT * +FROM orders +WHERE salesman_id IN + (SELECT salesman_id + FROM salesman + WHERE city ='New York'); \ No newline at end of file diff --git a/sql/Subqueries/6. Write a query to display the commission of all the salesmen servicing customers in Paris.sql b/sql/Subqueries/6. Write a query to display the commission of all the salesmen servicing customers in Paris.sql new file mode 100644 index 0000000..29162d2 --- /dev/null +++ b/sql/Subqueries/6. Write a query to display the commission of all the salesmen servicing customers in Paris.sql @@ -0,0 +1,7 @@ +/*6. Write a query to display the commission of all the salesmen servicing customers in Paris.*/ +SELECT commission +FROM salesman +WHERE salesman_id IN + (SELECT salesman_id + FROM customer + WHERE city = 'Paris'); \ No newline at end of file diff --git a/sql/Subqueries/7. Write a query to display all the customers whose id is 2001 bellow the salesman ID of Mc Lyon.sql b/sql/Subqueries/7. Write a query to display all the customers whose id is 2001 bellow the salesman ID of Mc Lyon.sql new file mode 100644 index 0000000..8b49379 --- /dev/null +++ b/sql/Subqueries/7. Write a query to display all the customers whose id is 2001 bellow the salesman ID of Mc Lyon.sql @@ -0,0 +1,7 @@ +/*7. Write a query to display all the customers whose id is 2001 bellow the salesman ID of Mc Lyon.*/ +SELECT * +FROM customer +WHERE customer_id = + (SELECT salesman_id -2001 + FROM salesman + WHERE name = 'Mc Lyon'); \ No newline at end of file diff --git a/sql/Subqueries/8. Write a query to counts the customers with grades above New York's average.sql b/sql/Subqueries/8. Write a query to counts the customers with grades above New York's average.sql new file mode 100644 index 0000000..378015b --- /dev/null +++ b/sql/Subqueries/8. Write a query to counts the customers with grades above New York's average.sql @@ -0,0 +1,7 @@ +SELECT grade, COUNT (DISTINCT customer_id) +FROM customer +GROUP BY grade +HAVING grade > + (SELECT AVG(grade) + FROM customer + WHERE city = 'New York'); \ No newline at end of file diff --git a/sql/Subqueries/9. Write a query to display all customers with orders on October 5, 2012.sql b/sql/Subqueries/9. Write a query to display all customers with orders on October 5, 2012.sql new file mode 100644 index 0000000..bdddc9c --- /dev/null +++ b/sql/Subqueries/9. Write a query to display all customers with orders on October 5, 2012.sql @@ -0,0 +1,5 @@ +/*9. Write a query to display all customers with orders on October 5, 2012.*/ +SELECT * +FROM customer a,orders b +WHERE a.customer_id=b.customer_id +AND b.ord_date='2012-10-05'; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Display the employee name( first name and last name ), employee id, and job title for all employees.sql b/sql/SubqueriesHRDatabase/Display the employee name( first name and last name ), employee id, and job title for all employees.sql new file mode 100644 index 0000000..b3f5bd7 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Display the employee name( first name and last name ), employee id, and job title for all employees.sql @@ -0,0 +1,13 @@ +/*Display the employee name( first name and last name ), employee id, and job title for all employees whose department location is Toronto. + +*/ + + SELECT first_name, last_name, employee_id, job_id + FROM employees + WHERE department_id = + (SELECT department_id + FROM departments + WHERE location_id = + (SELECT location_id + FROM locations + WHERE city ='Toronto')); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the city of the employee whose ID 134 and works there.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the city of the employee whose ID 134 and works there.sql new file mode 100644 index 0000000..e2aa2da --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the city of the employee whose ID 134 and works there.sql @@ -0,0 +1,11 @@ +/*Write a query in SQL to display the city of the employee whose ID 134 and works there.*/ + + SELECT city + FROM locations + WHERE location_id = + (SELECT location_id + FROM departments + WHERE department_id = + (SELECT department_id + FROM employees + WHERE employee_id=134)); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the department code and name for all departments which located in the city London.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the department code and name for all departments which located in the city London.sql new file mode 100644 index 0000000..4a518d2 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the department code and name for all departments which located in the city London.sql @@ -0,0 +1,11 @@ +/*Write a query in SQL to display the department code and name for all departments which located in the city London. +*/ + + SELECT department_id, department_name + FROM departments + WHERE location_id = + ( + SELECT location_id + FROM locations + WHERE city = 'London' + ); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the department name and Id for all departments where they located, that Id is equal to the Id for the location.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the department name and Id for all departments where they located, that Id is equal to the Id for the location.sql new file mode 100644 index 0000000..05b068f --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the department name and Id for all departments where they located, that Id is equal to the Id for the location.sql @@ -0,0 +1,12 @@ +/*Write a query in SQL to display the department name and Id for all departments where they located, that Id is equal to the + Id for the location where department number 30 is located. + +*/ + + SELECT department_name, department_id + FROM departments + WHERE location_id = + ( + SELECT location_id + FROM departments + WHERE department_id = 30); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the detail information of those departments which starting salary is at least 8000.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the detail information of those departments which starting salary is at least 8000.sql new file mode 100644 index 0000000..a94af78 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the detail information of those departments which starting salary is at least 8000.sql @@ -0,0 +1,9 @@ +/*Write a query in SQL to display the detail information of those departments which starting salary is at least 8000. + +*/ + SELECT * FROM departments + WHERE department_id IN + ( SELECT department_id + FROM employees + GROUP BY department_id + HAVING MIN(salary)>=8000); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, and department code for all.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, and department code for all.sql new file mode 100644 index 0000000..acaabe5 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, and department code for all.sql @@ -0,0 +1,11 @@ +/*Write a query in SQL to display the first and last name, and department code for all employees who work in the department +Marketing. + +*/ + + SELECT first_name, last_name, department_id + FROM employees + WHERE department_id = + (SELECT department_id + FROM departments + WHERE department_name = 'Marketing'); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary and department ID for those employees.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary and department ID for those employees.sql new file mode 100644 index 0000000..b3c7077 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary and department ID for those employees.sql @@ -0,0 +1,13 @@ +/*Write a query in SQL to display the first and last name, salary and department ID for those employees whose department is + located in the city London. +*/ + + SELECT first_name, last_name, salary, department_id + FROM employees + WHERE department_id IN + (SELECT department_id + FROM departments + WHERE location_id = + (SELECT location_id + FROM locations + WHERE city = 'London')); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for all those employees who work in that department.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for all those employees who work in that department.sql new file mode 100644 index 0000000..5e31b98 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for all those employees who work in that department.sql @@ -0,0 +1,9 @@ +/*Write a query in SQL to display the first and last name, salary, and department ID for all those employees who work in that department where the employee works who hold the ID 201. +*/ + + SELECT first_name, last_name, salary, department_id + FROM employees + WHERE department_id = + (SELECT department_id + FROM employees + WHERE employee_id = 201); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than the average salary, and also work at the department.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than the average salary, and also work at the department.sql new file mode 100644 index 0000000..5ffa7fd --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than the average salary, and also work at the department.sql @@ -0,0 +1,13 @@ +/*Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than + the average salary, and also work at the department where the employee Laura is working as a first name holder. +*/ + + SELECT first_name, last_name, salary, department_id + FROM employees + WHERE salary < + (SELECT AVG(salary) + FROM employees ) + AND department_id = + (SELECT department_id + FROM employees + WHERE first_name = 'Laura'); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than the minimum salary of a department which ID is 70.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than the minimum salary of a department which ID is 70.sql new file mode 100644 index 0000000..44541a2 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than the minimum salary of a department which ID is 70.sql @@ -0,0 +1,10 @@ +/*Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn less than +the minimum salary of a department which ID is 70.*/ + + + SELECT first_name, last_name, salary, department_id + FROM employees + WHERE salary < ALL + (SELECT salary + FROM employees + WHERE department_id = 70); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the maximum salary of a department which ID is 40.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the maximum salary of a department which ID is 40.sql new file mode 100644 index 0000000..86215d4 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the maximum salary of a department which ID is 40.sql @@ -0,0 +1,10 @@ +/*Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than + the maximum salary of a department which ID is 40. +*/ + + SELECT first_name, last_name, salary, department_id + FROM employees + WHERE salary > ALL + (SELECT salary + FROM employees + WHERE department_id = 40); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the minimum salary of a department which ID is 40.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the minimum salary of a department which ID is 40.sql new file mode 100644 index 0000000..e69c415 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the minimum salary of a department which ID is 40.sql @@ -0,0 +1,9 @@ +/*Write a query in SQL to display the first and last name, salary, and department ID for those employees who earn more than the minimum salary of a department which ID is 40. +*/ + + SELECT first_name, last_name, salary, department_id + FROM employees + WHERE salary > ANY + (SELECT salary + FROM employees + WHERE department_id = 40); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees whose salary is equal to the salary.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees whose salary is equal to the salary.sql new file mode 100644 index 0000000..9cb11b6 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the first and last name, salary, and department ID for those employees whose salary is equal to the salary.sql @@ -0,0 +1,10 @@ +/*Write a query in SQL to display the first and last name, salary, and department ID for those employees whose salary is equal + to the salary of the employee who works in that department which ID is 40. +*/ + + SELECT first_name, last_name, salary, department_id + FROM employees + WHERE salary IN ( + SELECT salary + FROM employees + WHERE department_id = 40); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the full name (first and last name) of manager who is supervising 4 or more employees.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the full name (first and last name) of manager who is supervising 4 or more employees.sql new file mode 100644 index 0000000..00084e4 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the full name (first and last name) of manager who is supervising 4 or more employees.sql @@ -0,0 +1,10 @@ +/*Write a query in SQL to display the full name (first and last name) of manager who is supervising 4 or more employees. +*/ + + SELECT first_name || ' ' || last_name AS Manager_name,department_id + FROM employees + WHERE employee_id IN + (SELECT manager_id + FROM employees + GROUP BY manager_id + HAVING COUNT(*)>=4); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the full name,email, and designation for all those employees who was hired after the employee whose ID is 165.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the full name,email, and designation for all those employees who was hired after the employee whose ID is 165.sql new file mode 100644 index 0000000..f53bf1d --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the full name,email, and designation for all those employees who was hired after the employee whose ID is 165.sql @@ -0,0 +1,9 @@ +/*Write a query in SQL to display the full name,email, and designation for all those employees who was hired after the employee whose ID is 165. +*/ + + SELECT first_name ||' '|| last_name AS Full_Name , hire_date + FROM employees + WHERE hire_date > ( + SELECT hire_date + FROM employees + WHERE employee_id = 165); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query in SQL to display the the details of those departments which max salary is 7000 or above for those employees.sql b/sql/SubqueriesHRDatabase/Write a query in SQL to display the the details of those departments which max salary is 7000 or above for those employees.sql new file mode 100644 index 0000000..4801aa4 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query in SQL to display the the details of those departments which max salary is 7000 or above for those employees.sql @@ -0,0 +1,14 @@ +/*Write a query in SQL to display the the details of those departments which max salary is 7000 or above for those employees + who already done one or more jobs. +*/ + + SELECT * + FROM departments + WHERE department_id IN + (SELECT department_id + FROM employees + WHERE employee_id IN + (SELECT employee_id + FROM job_history) + GROUP BY department_id + HAVING MAX(salary) >=7000); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query that will identify all employees who work in departments located in the United Kingdom.sql b/sql/SubqueriesHRDatabase/Write a query that will identify all employees who work in departments located in the United Kingdom.sql new file mode 100644 index 0000000..a37a137 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query that will identify all employees who work in departments located in the United Kingdom.sql @@ -0,0 +1,16 @@ +/*Write a query that will identify all employees who work in departments located in the United Kingdom. + +*/ + + SELECT first_name + FROM employees + WHERE department_id IN + (SELECT department_id + FROM departments + WHERE location_id IN + (SELECT location_id + FROM locations + WHERE country_id = + (SELECT country_id + FROM countries + WHERE country_name='United Kingdom'))); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to determine who earns more than Mr. Ozer.sql b/sql/SubqueriesHRDatabase/Write a query to determine who earns more than Mr. Ozer.sql new file mode 100644 index 0000000..cdcc94f --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to determine who earns more than Mr. Ozer.sql @@ -0,0 +1,10 @@ +/*Write a query to determine who earns more than Mr. Ozer. +*/ + + SELECT first_name, last_name, salary + FROM employees + WHERE salary > + (SELECT salary + FROM employees + WHERE last_name='Ozer') + ORDER BY last_name; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display all the information for those employees whose id is any id who earn the second highest salary.sql b/sql/SubqueriesHRDatabase/Write a query to display all the information for those employees whose id is any id who earn the second highest salary.sql new file mode 100644 index 0000000..84ed0d1 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display all the information for those employees whose id is any id who earn the second highest salary.sql @@ -0,0 +1,14 @@ +/*Write a query to display all the information for those employees whose id is any id who earn the second highest salary. +*/ + + SELECT * + FROM employees + WHERE employee_id IN + (SELECT employee_id + FROM employees + WHERE salary = + (SELECT MAX(salary) + FROM employees + WHERE salary < + (SELECT MAX(salary) + FROM employees))); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 respectively..sql b/sql/SubqueriesHRDatabase/Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 respectively..sql new file mode 100644 index 0000000..d3fab25 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 respectively..sql @@ -0,0 +1,7 @@ +/*Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 respectively. +*/ + + SELECT * + FROM employees + WHERE (salary,manager_id)= + (SELECT 3000,121); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 respectively.sql b/sql/SubqueriesHRDatabase/Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 respectively.sql new file mode 100644 index 0000000..fdc5686 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 respectively.sql @@ -0,0 +1,6 @@ +/*Write a query to display all the information of an employee whose salary and reporting person id is 3000 and 121 +respectively.*/ +SELECT * +FROM employees +WHERE (salary,manager_id)= +(SELECT 3000,121); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display all the information of the employees who does not work in those departments where some employees works.sql b/sql/SubqueriesHRDatabase/Write a query to display all the information of the employees who does not work in those departments where some employees works.sql new file mode 100644 index 0000000..ef26b74 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display all the information of the employees who does not work in those departments where some employees works.sql @@ -0,0 +1,9 @@ +/*Write a query to display all the information of the employees who does not work in those departments where some employees works whose id within the range 100 and 200. +*/ + + SELECT * + FROM employees + WHERE department_id NOT IN + (SELECT department_id + FROM departments + WHERE manager_id BETWEEN 100 AND 200); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display all the information of the employees whose salary if within the range of smallest salary and 2500.sql b/sql/SubqueriesHRDatabase/Write a query to display all the information of the employees whose salary if within the range of smallest salary and 2500.sql new file mode 100644 index 0000000..e1a4584 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display all the information of the employees whose salary if within the range of smallest salary and 2500.sql @@ -0,0 +1,7 @@ +/*Write a query to display all the information of the employees whose salary if within the range of smallest salary and 2500*/ + + SELECT * + FROM employees + WHERE salary BETWEEN + (SELECT MIN(salary) + FROM employees) AND 2500; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display all the information of the employees whose salary is within the range 1000 and 3000.sql b/sql/SubqueriesHRDatabase/Write a query to display all the information of the employees whose salary is within the range 1000 and 3000.sql new file mode 100644 index 0000000..686b96c --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display all the information of the employees whose salary is within the range 1000 and 3000.sql @@ -0,0 +1,5 @@ +/*Write a query to display all the information of the employees whose salary is within the range 1000 and 3000. +*/ + + SELECT * FROM employees + WHERE salary BETWEEN 1000 and 3000; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the ( first name and last name ) and job title for all employees whose salary.sql b/sql/SubqueriesHRDatabase/Write a query to display the ( first name and last name ) and job title for all employees whose salary.sql new file mode 100644 index 0000000..f800198 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the ( first name and last name ) and job title for all employees whose salary.sql @@ -0,0 +1,11 @@ +/*Write a query to display the employee number, name( first name and last name ) and job title for all employees whose salary + is more than any salary of those employees whose job title is PU_MAN. Exclude job title PU_MAN. +*/ + + SELECT employee_id, first_name, last_name, job_id + FROM employees + WHERE salary > ALL + ( SELECT salary + FROM employees + WHERE job_id = 'PU_MAN' ) + AND job_id <> 'PU_MAN' ; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the department id and the total salary for those departments which contains at least one salaried employee.sql b/sql/SubqueriesHRDatabase/Write a query to display the department id and the total salary for those departments which contains at least one salaried employee.sql new file mode 100644 index 0000000..34a49f5 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the department id and the total salary for those departments which contains at least one salaried employee.sql @@ -0,0 +1,11 @@ +/*Write a query to display the department id and the total salary for those departments which contains at least one salaried + employee. + +*/ + + SELECT departments.department_id, result1.total_amt + FROM departments, + ( SELECT employees.department_id, SUM(employees.salary) total_amt + FROM employees + GROUP BY department_id) result1 + WHERE result1.department_id = departments.department_id; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee id, employee name (first name and last name ) for all employees who earn more than the average salary.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee id, employee name (first name and last name ) for all employees who earn more than the average salary.sql new file mode 100644 index 0000000..30dd9b7 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee id, employee name (first name and last name ) for all employees who earn more than the average salary.sql @@ -0,0 +1,8 @@ +/*Write a query to display the employee id, employee name (first name and last name ) for all employees who earn more than the + average salary.*/ +SELECT employee_id, first_name,last_name +FROM employees +WHERE salary > +( SELECT AVG(salary) +FROM employees +); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ) and the job id column with a modified title SALESMAN for those employees whose job title is.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ) and the job id column with a modified title SALESMAN for those employees whose job title is.sql new file mode 100644 index 0000000..b022df2 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ) and the job id column with a modified title SALESMAN for those employees whose job title is.sql @@ -0,0 +1,12 @@ +/*Write a query to display the employee id, name ( first name and last name ) and the job id column with a modified title + SALESMAN for those employees whose job title is ST_MAN and DEVELOPER for whose job title is IT_PROG. + +*/ + + SELECT employee_id, first_name, last_name, + CASE job_id + WHEN 'ST_MAN' THEN 'SALESMAN' + WHEN 'IT_PROG' THEN 'DEVELOPER' + ELSE job_id + END AS designation, salary + FROM employees; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), SalaryDrawn, AvgCompare (salary - the average salary of all employees) and the SalaryStatus.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), SalaryDrawn, AvgCompare (salary - the average salary of all employees) and the SalaryStatus.sql new file mode 100644 index 0000000..07977f0 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), SalaryDrawn, AvgCompare (salary - the average salary of all employees) and the SalaryStatus.sql @@ -0,0 +1,14 @@ +/*Write a query to display the employee id, name ( first name and last name ), SalaryDrawn, AvgCompare (salary - the average + salary of all employees) and the SalaryStatus column with a title HIGH and LOW respectively for those employees whose + salary is more than and less than the average salary of all employees. + +*/ + + SELECT employee_id, first_name, last_name, salary AS SalaryDrawn, + ROUND((salary -(SELECT AVG(salary) FROM employees)),2) AS AvgCompare, + CASE WHEN salary >= + (SELECT AVG(salary) + FROM employees) THEN 'HIGH' + ELSE 'LOW' + END AS SalaryStatus + FROM employees; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), salary and the SalaryStatus column with a title HIGH and LOW.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), salary and the SalaryStatus column with a title HIGH and LOW.sql new file mode 100644 index 0000000..b1dfe61 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), salary and the SalaryStatus column with a title HIGH and LOW.sql @@ -0,0 +1,12 @@ +/*Write a query to display the employee id, name ( first name and last name ), salary and the SalaryStatus column with a title + HIGH and LOW respectively for those employees whose salary is more than and less than the average salary of all employees. + +*/ + + SELECT employee_id, first_name, last_name, salary, + CASE WHEN salary >= + (SELECT AVG(salary) + FROM employees) THEN 'HIGH' + ELSE 'LOW' + END AS SalaryStatus + FROM employees; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), salary, department.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), salary, department.sql new file mode 100644 index 0000000..5857e44 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee id, name ( first name and last name ), salary, department.sql @@ -0,0 +1,13 @@ +/*Write a query to display the employee id, name ( first name and last name ), salary, department name and city for all the + employees who gets the salary as the salary earn by the employee which is maximum within the joining person + January 1st, 2002 and December 31st, 2003. +*/ + + SELECT a.employee_id, a.first_name, a.last_name, a.salary, b.department_name, c.city + FROM employees a, departments b, locations c + WHERE a.salary = + (SELECT MAX(salary) + FROM employees + WHERE hire_date BETWEEN '01/01/2002' AND '12/31/2003') + AND a.department_id=b.department_id + AND b.location_id=c.location_id; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee name ( first name and last name ), employee id and salary of all employees who report to Payam.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee name ( first name and last name ), employee id and salary of all employees who report to Payam.sql new file mode 100644 index 0000000..1f062ea --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee name ( first name and last name ), employee id and salary of all employees who report to Payam.sql @@ -0,0 +1,9 @@ +/*Write a query to display the employee name ( first name and last name ), employee id and salary of all employees who report + to Payam.*/ +SELECT first_name, last_name, employee_id, salary +FROM employees +WHERE manager_id = +(SELECT employee_id +FROM employees +WHERE first_name = "Payam" +); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee name( first name and last name ) and department for all employees for any existence of those employees whose.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee name( first name and last name ) and department for all employees for any existence of those employees whose.sql new file mode 100644 index 0000000..f90aaf9 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee name( first name and last name ) and department for all employees for any existence of those employees whose.sql @@ -0,0 +1,10 @@ +/*Write a query to display the employee name( first name and last name ) and department for all employees for any existence + of those employees whose salary is more than 3700. +*/ + + SELECT first_name, last_name, department_id + FROM employees + WHERE EXISTS + (SELECT * + FROM employees + WHERE salary >3700 ); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee name( first name and last name ) and hiredate for all employees in the same department as Clara. Exclude Clara.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee name( first name and last name ) and hiredate for all employees in the same department as Clara. Exclude Clara.sql new file mode 100644 index 0000000..9ad74f4 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee name( first name and last name ) and hiredate for all employees in the same department as Clara. Exclude Clara.sql @@ -0,0 +1,11 @@ +/*Write a query to display the employee name( first name and last name ) and hiredate for all employees in the same department as Clara. Exclude Clara. + +*/ + + SELECT first_name, last_name, hire_date + FROM employees + WHERE department_id = + ( SELECT department_id + FROM employees + WHERE first_name = "Clara") + AND first_name <> "Clara"; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee number and name( first name and last name ) for all employees who work in a department with any employee whose name contains a T.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee number and name( first name and last name ) for all employees who work in a department with any employee whose name contains a T.sql new file mode 100644 index 0000000..3c33c98 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee number and name( first name and last name ) for all employees who work in a department with any employee whose name contains a T.sql @@ -0,0 +1,10 @@ +/*Write a query to display the employee number and name( first name and last name ) for all employees who work in a department with any employee whose name contains a T. + +*/ + + SELECT employee_id, first_name, last_name + FROM employees + WHERE department_id IN + ( SELECT department_id + FROM employees + WHERE first_name LIKE '%T%' ); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee number, name ob title for all employees whose salary is smaller than any.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee number, name ob title for all employees whose salary is smaller than any.sql new file mode 100644 index 0000000..3edfc1c --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee number, name ob title for all employees whose salary is smaller than any.sql @@ -0,0 +1,12 @@ +/*Write a query to display the employee number, name( first name and last name ) and job title for all employees whose salary is + smaller than any salary of those employees whose job title is MK_MAN. Exclude Job title MK_MAN. + +*/ + + SELECT employee_id,first_name,last_name, job_id + FROM employees + WHERE salary < ANY + ( SELECT salary + FROM employees + WHERE job_id = 'MK_MAN' ) + AND job_id <> 'MK_MAN' ; \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the employee number, name( first name and last name ) and job title for all employees whose salary is more.sql b/sql/SubqueriesHRDatabase/Write a query to display the employee number, name( first name and last name ) and job title for all employees whose salary is more.sql new file mode 100644 index 0000000..1691eb6 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the employee number, name( first name and last name ) and job title for all employees whose salary is more.sql @@ -0,0 +1,11 @@ +/*Write a query to display the employee number, name( first name and last name ) and job title for all employees whose salary +is more than any average salary of any department. +*/ + + SELECT employee_id, first_name, last_name, job_id + FROM employees + WHERE salary > ALL + ( SELECT AVG(salary) + FROM employees + GROUP BY department_id + ); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to display the name ( first name and last name ) for those employees who gets more salary than the employee whose id is 163.sql b/sql/SubqueriesHRDatabase/Write a query to display the name ( first name and last name ) for those employees who gets more salary than the employee whose id is 163.sql new file mode 100644 index 0000000..758292f --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to display the name ( first name and last name ) for those employees who gets more salary than the employee whose id is 163.sql @@ -0,0 +1,9 @@ +/*Write a query to display the name ( first name and last name ) for those employees who gets more salary than the employee + whose id is 163.*/ +SELECT first_name, last_name +FROM employees +WHERE salary > +( SELECT salary +FROM employees +WHERE employee_id=163 +); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to find out which employees have a manager who works for a department based in the US.sql b/sql/SubqueriesHRDatabase/Write a query to find out which employees have a manager who works for a department based in the US.sql new file mode 100644 index 0000000..b36b735 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to find out which employees have a manager who works for a department based in the US.sql @@ -0,0 +1,15 @@ +/*Write a query to find out which employees have a manager who works for a department based in the US. + +*/ + + SELECT first_name,last_name FROM employees + WHERE manager_id IN + (SELECT employee_id + FROM employees + WHERE department_id IN + (SELECT department_id + FROM departments + WHERE location_id IN + (SELECT location_id + FROM locations + WHERE country_id='US'))); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to get the details of employees who are managers.sql b/sql/SubqueriesHRDatabase/Write a query to get the details of employees who are managers.sql new file mode 100644 index 0000000..9b69d7d --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to get the details of employees who are managers.sql @@ -0,0 +1,9 @@ +/*Write a query to get the details of employees who are managers. +*/ + + SELECT * + FROM employees + WHERE EXISTS + (SELECT * + FROM departments + WHERE manager_id = employee_id); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to get the details of employees who manage a department.sql b/sql/SubqueriesHRDatabase/Write a query to get the details of employees who manage a department.sql new file mode 100644 index 0000000..c586f26 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to get the details of employees who manage a department.sql @@ -0,0 +1,7 @@ +/*Write a query to get the details of employees who manage a department. +*/ + + SELECT * + FROM employees + WHERE employee_id=ANY + ( SELECT manager_id FROM departments ); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query to identify all the employees who earn more than the average and who work in any of the IT departments.sql b/sql/SubqueriesHRDatabase/Write a query to identify all the employees who earn more than the average and who work in any of the IT departments.sql new file mode 100644 index 0000000..0043200 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query to identify all the employees who earn more than the average and who work in any of the IT departments.sql @@ -0,0 +1,12 @@ +/*Write a query to identify all the employees who earn more than the average and who work in any of the IT departments. +*/ + + SELECT last_name + FROM employees + WHERE department_id IN + (SELECT department_id + FROM departments + WHERE department_name LIKE 'IT%') + AND salary > + (SELECT avg(salary) + FROM employees); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a query which is looking for the names of all employees whose salary is greater than 50 of their departments total salary bill.sql b/sql/SubqueriesHRDatabase/Write a query which is looking for the names of all employees whose salary is greater than 50 of their departments total salary bill.sql new file mode 100644 index 0000000..5905db4 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a query which is looking for the names of all employees whose salary is greater than 50 of their departments total salary bill.sql @@ -0,0 +1,10 @@ +/*Write a query which is looking for the names of all employees whose salary is greater than 50% of their department’s + total salary bill. +*/ + + SELECT e1.first_name, e1.last_name + FROM employees e1 + WHERE salary > + ( SELECT (SUM(salary))*.5 + FROM employees e2 + WHERE e1.department_id=e2.department_id); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a statement to display all the information of an employee whose id is any of the number 134, 159 and 183.sql b/sql/SubqueriesHRDatabase/Write a statement to display all the information of an employee whose id is any of the number 134, 159 and 183.sql new file mode 100644 index 0000000..3fed929 --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a statement to display all the information of an employee whose id is any of the number 134, 159 and 183.sql @@ -0,0 +1,6 @@ +/*Write a statement to display all the information of an employee whose id is any of the number 134, 159 and 183.*/ + + + SELECT * + FROM employees + WHERE employee_id IN (134,159,183); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/Write a subquery that returns a set of rows to find all departments that do actually have one or more employees assigned to them.sql b/sql/SubqueriesHRDatabase/Write a subquery that returns a set of rows to find all departments that do actually have one or more employees assigned to them.sql new file mode 100644 index 0000000..530068a --- /dev/null +++ b/sql/SubqueriesHRDatabase/Write a subquery that returns a set of rows to find all departments that do actually have one or more employees assigned to them.sql @@ -0,0 +1,8 @@ +/*Write a subquery that returns a set of rows to find all departments that do actually have one or more employees assigned to them. +*/ + + SELECT department_name + FROM departments + WHERE department_id IN + (SELECT DISTINCT(department_id) + FROM employees); \ No newline at end of file diff --git a/sql/SubqueriesHRDatabase/to display the department number, name ( first name and last name ), job and department name for all employees in the Finance department.sql b/sql/SubqueriesHRDatabase/to display the department number, name ( first name and last name ), job and department name for all employees in the Finance department.sql new file mode 100644 index 0000000..a7b3627 --- /dev/null +++ b/sql/SubqueriesHRDatabase/to display the department number, name ( first name and last name ), job and department name for all employees in the Finance department.sql @@ -0,0 +1,6 @@ +/* to display the department number, name ( first name and last name ), job and department name for all employees in the +Finance department.*/ + SELECT e.department_id, e.first_name, e.job_id , d.department_name + FROM employees e , departments d + WHERE e.department_id = d.department_id + AND d.department_name = "Finance"; \ No newline at end of file diff --git a/sql/Union/1. Write a query to display all salesmen and customer located in London.sql b/sql/Union/1. Write a query to display all salesmen and customer located in London.sql new file mode 100644 index 0000000..7890bc1 --- /dev/null +++ b/sql/Union/1. Write a query to display all salesmen and customer located in London.sql @@ -0,0 +1,8 @@ + /*1. Write a query to display all salesmen and customer located in London.*/ + SELECT salesman_id, name + FROM salesman + WHERE city='London' + UNION + SELECT customer_id, cust_name + FROM customer + WHERE city='London'; \ No newline at end of file diff --git a/sql/Union/2. Write a query to display distinct salesman and their cities.sql b/sql/Union/2. Write a query to display distinct salesman and their cities.sql new file mode 100644 index 0000000..47c53aa --- /dev/null +++ b/sql/Union/2. Write a query to display distinct salesman and their cities.sql @@ -0,0 +1,6 @@ +/*2. Write a query to display distinct salesman and their cities.*/ +SELECT salesman_id, city +FROM customer +UNION +SELECT salesman_id, city +FROM salesman; \ No newline at end of file diff --git a/sql/Union/3. Write a query to display all the salesmen and customer involved in this inventory management system.sql b/sql/Union/3. Write a query to display all the salesmen and customer involved in this inventory management system.sql new file mode 100644 index 0000000..54d65e3 --- /dev/null +++ b/sql/Union/3. Write a query to display all the salesmen and customer involved in this inventory management system.sql @@ -0,0 +1,6 @@ +/*3. Write a query to display all the salesmen and customer involved in this inventory management system.*/ +SELECT salesman_id, customer_id +FROM customer +UNION +SELECT salesman_id, customer_id +FROM orders; \ No newline at end of file diff --git a/sql/Union/4. Write a query to make a report of which salesman produce the largest and smallest orders on each date.sql b/sql/Union/4. Write a query to make a report of which salesman produce the largest and smallest orders on each date.sql new file mode 100644 index 0000000..a037c34 --- /dev/null +++ b/sql/Union/4. Write a query to make a report of which salesman produce the largest and smallest orders on each date.sql @@ -0,0 +1,16 @@ +/*4. Write a query to make a report of which salesman produce the largest and smallest orders on each date.*/ +SELECT a.salesman_id, name, ord_no, 'highest on', ord_date +FROM salesman a, orders b +WHERE a.salesman_id =b.salesman_id +AND b.purch_amt= + (SELECT MAX (purch_amt) + FROM orders c + WHERE c.ord_date = b.ord_date) +UNION +SELECT a.salesman_id, name, ord_no, 'lowest on', ord_date +FROM salesman a, orders b +WHERE a.salesman_id =b.salesman_id +AND b.purch_amt= + (SELECT MIN (purch_amt) + FROM orders c + WHERE c.ord_date = b.ord_date); \ No newline at end of file diff --git a/sql/Union/5. Write a query to make a report of which salesman produce the largest and smallest orders on each date and arranged the orders number in smallest to the largest number.sql b/sql/Union/5. Write a query to make a report of which salesman produce the largest and smallest orders on each date and arranged the orders number in smallest to the largest number.sql new file mode 100644 index 0000000..f111a3a --- /dev/null +++ b/sql/Union/5. Write a query to make a report of which salesman produce the largest and smallest orders on each date and arranged the orders number in smallest to the largest number.sql @@ -0,0 +1,18 @@ +/*5. Write a query to make a report of which salesman produce the largest and smallest orders on each date and arranged the + orders number in smallest to the largest number. */ +SELECT a.salesman_id, name, ord_no, 'highest on', ord_date +FROM salesman a, orders b +WHERE a.salesman_id =b.salesman_id +AND b.purch_amt= + (SELECT MAX (purch_amt) + FROM orders c + WHERE c.ord_date = b.ord_date) +UNION +SELECT a.salesman_id, name, ord_no, 'lowest on', ord_date +FROM salesman a, orders b +WHERE a.salesman_id =b.salesman_id +AND b.purch_amt= + (SELECT MIN (purch_amt) + FROM orders c + WHERE c.ord_date = b.ord_date) +ORDER BY 3; \ No newline at end of file diff --git a/sql/Union/6. Write a query to list all the salesmen, and indicate those who do not have customers in their cities, as well as whose who do.sql b/sql/Union/6. Write a query to list all the salesmen, and indicate those who do not have customers in their cities, as well as whose who do.sql new file mode 100644 index 0000000..d19c99c --- /dev/null +++ b/sql/Union/6. Write a query to list all the salesmen, and indicate those who do not have customers in their cities, as well as whose who do.sql @@ -0,0 +1,12 @@ +/*6. Write a query to list all the salesmen, and indicate those who do not have customers in their cities, as well as whose +who do.*/ +SELECT salesman.salesman_id, name, cust_name, commission +FROM salesman, customer +WHERE salesman.city = customer.city +UNION +SELECT salesman_id, name, 'NO MATCH', commission +FROM salesman +WHERE NOT city = ANY + (SELECT city + FROM customer) +ORDER BY 2 DESC; \ No newline at end of file diff --git a/sql/Union/7. Write a query to that appends strings to the selected fields, indicating whether or not a specified salesman was matched to a customer in his city.sql b/sql/Union/7. Write a query to that appends strings to the selected fields, indicating whether or not a specified salesman was matched to a customer in his city.sql new file mode 100644 index 0000000..8b8dc0c --- /dev/null +++ b/sql/Union/7. Write a query to that appends strings to the selected fields, indicating whether or not a specified salesman was matched to a customer in his city.sql @@ -0,0 +1,12 @@ +/*7. Write a query to that appends strings to the selected fields, indicating whether or not a specified salesman was matched + to a customer in his city.*/ +SELECT a.salesman_id, name, a.city, 'MATCHED' +FROM salesman a, customer b +WHERE a.city = b.city +UNION +SELECT salesman_id, name, city, 'NO MATCH' +FROM salesman +WHERE NOT city = ANY + (SELECT city + FROM customer) +ORDER BY 2 DESC; \ No newline at end of file diff --git a/sql/Union/8. Write a query to create a union of two queries that shows the names, cities, and ratings of all customers. Those with a rating of 300 or greater.sql b/sql/Union/8. Write a query to create a union of two queries that shows the names, cities, and ratings of all customers. Those with a rating of 300 or greater.sql new file mode 100644 index 0000000..0fc2196 --- /dev/null +++ b/sql/Union/8. Write a query to create a union of two queries that shows the names, cities, and ratings of all customers. Those with a rating of 300 or greater.sql @@ -0,0 +1,9 @@ +/*8. Write a query to create a union of two queries that shows the names, cities, and ratings of all customers. Those with + a rating of 300 or greater will also have the words High Rating, while the others will have the words Low Rating.*/ + SELECT customer_id, city, grade, 'High Rating' + FROM customer + WHERE grade >= 300 + UNION + SELECT customer_id, city, grade, 'Low Rating' + FROM customer + WHERE grade < 300; \ No newline at end of file diff --git a/sql/Union/9. Write a query that produces the name and number of each salesman and each customer with more than one current order. Put the results in alphabetical order.sql b/sql/Union/9. Write a query that produces the name and number of each salesman and each customer with more than one current order. Put the results in alphabetical order.sql new file mode 100644 index 0000000..fec0b1c --- /dev/null +++ b/sql/Union/9. Write a query that produces the name and number of each salesman and each customer with more than one current order. Put the results in alphabetical order.sql @@ -0,0 +1,16 @@ +/*9. Write a query that produces the name and number of each salesman and each customer with more than one current order. + Put the results in alphabetical order.*/ +SELECT customer_id, cust_name + FROM customer a + WHERE 1< + (SELECT COUNT (*) + FROM orders b + WHERE a.customer_id = b.customer_id) +UNION +SELECT salesman_id, name + FROM salesman a + WHERE 1 < + (SELECT COUNT (*) + FROM orders b + WHERE a.salesman_id = b.salesman_id) +ORDER BY 2; \ No newline at end of file diff --git a/sql/UserManagement/1. How to create a user on localhost.sql b/sql/UserManagement/1. How to create a user on localhost.sql new file mode 100644 index 0000000..d21d209 --- /dev/null +++ b/sql/UserManagement/1. How to create a user on localhost.sql @@ -0,0 +1,11 @@ +/*1. How to create a user on localhost.*/ + + + +/*Syntax : + +create user [user name]@[||] +identified by ["password"];*/ + + +create user ramaswamy@localhost identified by "mypasword"; diff --git a/sql/UserManagement/10. How to check permissions granted to a specific user.sql b/sql/UserManagement/10. How to check permissions granted to a specific user.sql new file mode 100644 index 0000000..b9cb5a2 --- /dev/null +++ b/sql/UserManagement/10. How to check permissions granted to a specific user.sql @@ -0,0 +1,4 @@ +/*10. How to check permissions granted to a specific user. +*/ + +show grants for amit; diff --git a/sql/UserManagement/11. How to check the list of system privileges that the MySQL server supports.sql b/sql/UserManagement/11. How to check the list of system privileges that the MySQL server supports.sql new file mode 100644 index 0000000..255feab --- /dev/null +++ b/sql/UserManagement/11. How to check the list of system privileges that the MySQL server supports.sql @@ -0,0 +1,4 @@ +/*11. How to check the list of system privileges that the MySQL server supports. +*/ + +show privileges; diff --git a/sql/UserManagement/12. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour.sql b/sql/UserManagement/12. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour.sql new file mode 100644 index 0000000..d83b5dc --- /dev/null +++ b/sql/UserManagement/12. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour.sql @@ -0,0 +1,7 @@ +/*12. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour. +*/ + +create user steffi@localhost identified by 'mypassword'; +grant select on posts.* to steffi@localhost +identified by 'mypassword' with MAX_QUERIES_PER_HOUR 50; +flush privileges; diff --git a/sql/UserManagement/13. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour.sql b/sql/UserManagement/13. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour.sql new file mode 100644 index 0000000..673dcc7 --- /dev/null +++ b/sql/UserManagement/13. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour.sql @@ -0,0 +1,4 @@ +/*13. How to Grant permission to a user so that (s)he can execute not more than a specific number of queries in an hour. +*/ + +set password for steffi@localhost = password('mypassword123'); diff --git a/sql/UserManagement/14. How to delete user.sql b/sql/UserManagement/14. How to delete user.sql new file mode 100644 index 0000000..ad7772f --- /dev/null +++ b/sql/UserManagement/14. How to delete user.sql @@ -0,0 +1,4 @@ +/*14. How to delete user. +*/ + +drop user steffi@'localhost'; diff --git a/sql/UserManagement/15. How to rename a user.sql b/sql/UserManagement/15. How to rename a user.sql new file mode 100644 index 0000000..9946e2b --- /dev/null +++ b/sql/UserManagement/15. How to rename a user.sql @@ -0,0 +1,5 @@ +/*15. How to rename a user. +*/ + + +rename user amit@localhost to sumit@localhost; diff --git a/sql/UserManagement/16. How to create a user and granting no privileges.sql b/sql/UserManagement/16. How to create a user and granting no privileges.sql new file mode 100644 index 0000000..dae18f5 --- /dev/null +++ b/sql/UserManagement/16. How to create a user and granting no privileges.sql @@ -0,0 +1,4 @@ +/*16. How to create a user and granting no privileges +*/ + +grant usage on posts.* to boris@localhost identified by 'mypassword'; diff --git a/sql/UserManagement/2. How to create a user for an IP address other than localhost.sql b/sql/UserManagement/2. How to create a user for an IP address other than localhost.sql new file mode 100644 index 0000000..f6f45f1 --- /dev/null +++ b/sql/UserManagement/2. How to create a user for an IP address other than localhost.sql @@ -0,0 +1,12 @@ +/*2. How to create a user for an IP address other than localhost.*/ + + +/*Syntax : + +create user [user name]@[||] +identified by ["password"]; +*/ + + + +create user ramaswamy@192.168.0.105 identified by "mypasword"; \ No newline at end of file diff --git a/sql/UserManagement/3. How to grant permission to a user to select only from localhost.sql b/sql/UserManagement/3. How to grant permission to a user to select only from localhost.sql new file mode 100644 index 0000000..8800427 --- /dev/null +++ b/sql/UserManagement/3. How to grant permission to a user to select only from localhost.sql @@ -0,0 +1,12 @@ +/*3. How to grant permission to a user to select only from localhost. +*/ +/*Syntax : + +grant [|] +on [database].[|] +to [user name]@[||] +identified by ["password"]; +*/ + +grant select on posts.* to ramaswamy@localhost identified by 'mypassword'; +flush privileges; diff --git a/sql/UserManagement/4. How to grant a user permission to create, insert, update, delete and create temporary tables from localhost.sql b/sql/UserManagement/4. How to grant a user permission to create, insert, update, delete and create temporary tables from localhost.sql new file mode 100644 index 0000000..a9807a3 --- /dev/null +++ b/sql/UserManagement/4. How to grant a user permission to create, insert, update, delete and create temporary tables from localhost.sql @@ -0,0 +1,13 @@ +/*4. How to grant a user permission to create, insert, update, delete and create temporary tables from localhost. +*/ +/*Syntax : + +grant [|] +on [database].[|] +to [user name]@[||] +identified by ["password"]; +*/ + +grant select, create, insert, update, delete, create temporary tables +on posts.* to amit@localhost identified by 'mypassword'; +flush privileges; diff --git a/sql/UserManagement/5. How to grant a user permission to create, insert, update, delete and create temporary tables from any host.sql b/sql/UserManagement/5. How to grant a user permission to create, insert, update, delete and create temporary tables from any host.sql new file mode 100644 index 0000000..ee852f0 --- /dev/null +++ b/sql/UserManagement/5. How to grant a user permission to create, insert, update, delete and create temporary tables from any host.sql @@ -0,0 +1,13 @@ +/*5. How to grant a user permission to create, insert, update, delete and create temporary tables from any host. +*/ +/*Syntax : + +grant [|] +on [database].[|] +to [user name]@[||] +identified by ["password"]; +*/ + +grant select, create, insert, update, delete, create temporary tables on posts.* +to amit@'%' identified by 'mypassword'; +flush privileges; diff --git a/sql/UserManagement/6. How to grant a user permission to select only from any host but to a specific table of a database.sql b/sql/UserManagement/6. How to grant a user permission to select only from any host but to a specific table of a database.sql new file mode 100644 index 0000000..ea277af --- /dev/null +++ b/sql/UserManagement/6. How to grant a user permission to select only from any host but to a specific table of a database.sql @@ -0,0 +1,13 @@ +/*6. How to grant a user permission to select only from any host but to a specific table of a database. +*/ +/*Syntax : + +grant [|] +on [database].[|] +to [user name]@[||] +identified by ["password"]; +*/ + + +grant select on posts.url_master to jhon@'%' identified by 'mypassword'; +flush privileges; diff --git a/sql/UserManagement/7. How to grant all privileges to a user from all machines.sql b/sql/UserManagement/7. How to grant all privileges to a user from all machines.sql new file mode 100644 index 0000000..855bda1 --- /dev/null +++ b/sql/UserManagement/7. How to grant all privileges to a user from all machines.sql @@ -0,0 +1,13 @@ +/*7. How to grant all privileges to a user from all machines. +*/ +/*Syntax : + +grant [|] +on [database].[|] +to [user name]@[||] +identified by ["password"]; +*/ + + +grant all on posts.* to joy@'%' identified by 'mypassword'; +flush privileges; diff --git a/sql/UserManagement/8. How to revoke all privileges from a user.sql b/sql/UserManagement/8. How to revoke all privileges from a user.sql new file mode 100644 index 0000000..4f77bad --- /dev/null +++ b/sql/UserManagement/8. How to revoke all privileges from a user.sql @@ -0,0 +1,11 @@ +/*8. How to revoke all privileges from a user. +*/ +/*Syntax : + +revoke [|] +on [database].[|] +from [user name]@[||]; +*/ + +revoke all privileges on posts.* from joy@'%'; +flush privileges; diff --git a/sql/UserManagement/9. How to revoke specific privilege from a user.sql b/sql/UserManagement/9. How to revoke specific privilege from a user.sql new file mode 100644 index 0000000..aa2b691 --- /dev/null +++ b/sql/UserManagement/9. How to revoke specific privilege from a user.sql @@ -0,0 +1,12 @@ +/*9. How to revoke specific privilege from a user. +*/ +/*Syntax : + +revoke [|] +on [database].[|] +from [user name]@[||]; +*/ + + +revoke select on posts.* from joy@'%'; +flush privileges; diff --git a/sql/View/1. Write a query to create a view for those salesmen belongs to the city New York.sql b/sql/View/1. Write a query to create a view for those salesmen belongs to the city New York.sql new file mode 100644 index 0000000..23f6013 --- /dev/null +++ b/sql/View/1. Write a query to create a view for those salesmen belongs to the city New York.sql @@ -0,0 +1,5 @@ +/*1. Write a query to create a view for those salesmen belongs to the city New York.*/ +CREATE VIEW newyorkstaff +AS SELECT * +FROM salesman +WHERE city = 'New York'; \ No newline at end of file diff --git a/sql/View/10. Write a query to create a view that shows the number of the salesman in each city.sql b/sql/View/10. Write a query to create a view that shows the number of the salesman in each city.sql new file mode 100644 index 0000000..f4fa02d --- /dev/null +++ b/sql/View/10. Write a query to create a view that shows the number of the salesman in each city.sql @@ -0,0 +1,5 @@ +/*10. Write a query to create a view that shows the number of the salesman in each city.*/ +CREATE VIEW citynum +AS SELECT city, COUNT (DISTINCT salesman_id) +FROM salesman +GROUP BY city; \ No newline at end of file diff --git a/sql/View/11. Write a query to create a view that shows the average and total orders for each salesman after his or her name. (Assume all names are unique).sql b/sql/View/11. Write a query to create a view that shows the average and total orders for each salesman after his or her name. (Assume all names are unique).sql new file mode 100644 index 0000000..e69de29 diff --git a/sql/View/11. Write a query to create a view that shows the average and total orders for each salesman after his or her name.sql b/sql/View/11. Write a query to create a view that shows the average and total orders for each salesman after his or her name.sql new file mode 100644 index 0000000..b5dcb05 --- /dev/null +++ b/sql/View/11. Write a query to create a view that shows the average and total orders for each salesman after his or her name.sql @@ -0,0 +1,7 @@ +/*11. Write a query to create a view that shows the average and total orders for each salesman after his or her name. + (Assume all names are unique)*/ +CREATE VIEW norders +AS SELECT name, AVG(purch_amt), SUM(purch_amt) +FROM salesman, orders +WHERE salesman.salesman_id = orders.salesman_id +GROUP BY name; \ No newline at end of file diff --git a/sql/View/12. Write a query to create a view that shows each salesman with more than one customers.sql b/sql/View/12. Write a query to create a view that shows each salesman with more than one customers.sql new file mode 100644 index 0000000..14db4d8 --- /dev/null +++ b/sql/View/12. Write a query to create a view that shows each salesman with more than one customers.sql @@ -0,0 +1,8 @@ +/*12. Write a query to create a view that shows each salesman with more than one customers.*/ +CREATE VIEW mcustomer +AS SELECT * +FROM salesman a +WHERE 1 < + (SELECT COUNT(*) + FROM customer b + WHERE a.salesman_id = b.salesman_id); \ No newline at end of file diff --git a/sql/View/13. Write a query to create a view that shows all matches of customers with salesman.sql b/sql/View/13. Write a query to create a view that shows all matches of customers with salesman.sql new file mode 100644 index 0000000..a0c79ea --- /dev/null +++ b/sql/View/13. Write a query to create a view that shows all matches of customers with salesman.sql @@ -0,0 +1,6 @@ +/*13. Write a query to create a view that shows all matches of customers with salesman such that at least one customer in the + city of customer served by a salesman in the city of the salesman.*/ +CREATE VIEW citymatch(custcity, salescity) +AS SELECT DISTINCT a.city, b.city +FROM customer a, salesman b +WHERE a.salesman_id = b.salesman_id; \ No newline at end of file diff --git a/sql/View/14. Write a query to create a view that shows the number of orders in each day.sql b/sql/View/14. Write a query to create a view that shows the number of orders in each day.sql new file mode 100644 index 0000000..2e02791 --- /dev/null +++ b/sql/View/14. Write a query to create a view that shows the number of orders in each day.sql @@ -0,0 +1,5 @@ +/*14. Write a query to create a view that shows the number of orders in each day.*/ +CREATE VIEW dateord(ord_date, odcount) +AS SELECT ord_date, COUNT (*) +FROM orders +GROUP BY ord_date; \ No newline at end of file diff --git a/sql/View/15. Write a query to create a view that finds the salesmen who issued orders on October 10th, 2012.sql b/sql/View/15. Write a query to create a view that finds the salesmen who issued orders on October 10th, 2012.sql new file mode 100644 index 0000000..7d296b8 --- /dev/null +++ b/sql/View/15. Write a query to create a view that finds the salesmen who issued orders on October 10th, 2012.sql @@ -0,0 +1,8 @@ +/*15. Write a query to create a view that finds the salesmen who issued orders on October 10th, 2012.*/ +CREATE VIEW salesmanonoct +AS SELECT * +FROM salesman +WHERE salesman_id IN + (SELECT salesman_id + FROM orders + WHERE ord_date = '2012-10-10'); \ No newline at end of file diff --git a/sql/View/16. Write a query to create a view that find the salesmen who issued orders on either August 17th, 2012 or October 10th, 2012.sql b/sql/View/16. Write a query to create a view that find the salesmen who issued orders on either August 17th, 2012 or October 10th, 2012.sql new file mode 100644 index 0000000..8fd0001 --- /dev/null +++ b/sql/View/16. Write a query to create a view that find the salesmen who issued orders on either August 17th, 2012 or October 10th, 2012.sql @@ -0,0 +1,6 @@ +/*16. Write a query to create a view that find the salesmen who issued orders on either August 17th, 2012 or +October 10th, 2012.*/ +CREATE VIEW sorder +AS SELECT salesman_id, ord_no, customer_id +FROM orders +WHERE ord_date IN('2012-08-17', '2012-10-10'); \ No newline at end of file diff --git a/sql/View/2. Write a query to create a view for all salesmen with columns salesman_id, name and city.sql b/sql/View/2. Write a query to create a view for all salesmen with columns salesman_id, name and city.sql new file mode 100644 index 0000000..6dc76e5 --- /dev/null +++ b/sql/View/2. Write a query to create a view for all salesmen with columns salesman_id, name and city.sql @@ -0,0 +1,4 @@ +/*2. Write a query to create a view for all salesmen with columns salesman_id, name and city.*/ + CREATE VIEW salesown + AS SELECT salesman_id, name, city + FROM salesman; \ No newline at end of file diff --git a/sql/View/3. Write a query to find the salesmen of the city New York who achieved the commission more than 13%.sql b/sql/View/3. Write a query to find the salesmen of the city New York who achieved the commission more than 13%.sql new file mode 100644 index 0000000..b402717 --- /dev/null +++ b/sql/View/3. Write a query to find the salesmen of the city New York who achieved the commission more than 13%.sql @@ -0,0 +1,14 @@ +/*3. Write a query to find the salesmen of the city New York who achieved the commission more than 13%.*/ + +/*Code to create the view*/ + + CREATE VIEW newyorkstaff + AS SELECT * + FROM salesman + WHERE city = 'New York'; + +/*Code to see the records form the view*/ + + SELECT * + FROM newyorkstaff + WHERE commission > .13; \ No newline at end of file diff --git a/sql/View/4.Write a query to create a view to getting a count of how many customers we have at each level of a grade.sql b/sql/View/4.Write a query to create a view to getting a count of how many customers we have at each level of a grade.sql new file mode 100644 index 0000000..3afc470 --- /dev/null +++ b/sql/View/4.Write a query to create a view to getting a count of how many customers we have at each level of a grade.sql @@ -0,0 +1,5 @@ +/*4.Write a query to create a view to getting a count of how many customers we have at each level of a grade. */ +CREATE VIEW gradecount (grade, number) +AS SELECT grade, COUNT(*) +FROM customer +GROUP BY grade; \ No newline at end of file diff --git a/sql/View/5. Write a query to create a view to keeping track the number of customers ordering, number of salesmen attached.sql b/sql/View/5. Write a query to create a view to keeping track the number of customers ordering, number of salesmen attached.sql new file mode 100644 index 0000000..95d3142 --- /dev/null +++ b/sql/View/5. Write a query to create a view to keeping track the number of customers ordering, number of salesmen attached.sql @@ -0,0 +1,7 @@ +/*5. Write a query to create a view to keeping track the number of customers ordering, number of salesmen attached, average + amount of orders and the total amount of orders in a day.*/ +CREATE VIEW totalforday + AS SELECT ord_date, COUNT(DISTINCT customer_id), + AVG(purch_amt), SUM(purch_amt) + FROM orders + GROUP BY ord_date; \ No newline at end of file diff --git a/sql/View/6. Write a query to create a view that shows for each order the salesman and customer by name.sql b/sql/View/6. Write a query to create a view that shows for each order the salesman and customer by name.sql new file mode 100644 index 0000000..39f45c5 --- /dev/null +++ b/sql/View/6. Write a query to create a view that shows for each order the salesman and customer by name.sql @@ -0,0 +1,6 @@ +/*6. Write a query to create a view that shows for each order the salesman and customer by name.*/ +CREATE VIEW nameorders +AS SELECT ord_no, purch_amt, a.salesman_id, name, cust_name +FROM orders a, customer b, salesman c +WHERE a.customer_id = b.customer_id +AND a.salesman_id = c.salesman_id; \ No newline at end of file diff --git a/sql/View/7. Write a query to create a view that finds the salesman who has the customer with the highest order of a day.sql b/sql/View/7. Write a query to create a view that finds the salesman who has the customer with the highest order of a day.sql new file mode 100644 index 0000000..5c4d3aa --- /dev/null +++ b/sql/View/7. Write a query to create a view that finds the salesman who has the customer with the highest order of a day.sql @@ -0,0 +1,9 @@ +/*7. Write a query to create a view that finds the salesman who has the customer with the highest order of a day. */ +CREATE VIEW elitsalesman +AS SELECT b.ord_date, a.salesman_id, a.name +FROM salesman a, orders b +WHERE a.salesman_id = b.salesman_id +AND b.purch_amt = + (SELECT MAX (purch_amt) + FROM orders c + WHERE c.ord_date = b.ord_date); \ No newline at end of file diff --git a/sql/View/8. Write a query to create a view that finds the salesman who has the customer with the highest order at least 3 times on a day.sql b/sql/View/8. Write a query to create a view that finds the salesman who has the customer with the highest order at least 3 times on a day.sql new file mode 100644 index 0000000..81f0082 --- /dev/null +++ b/sql/View/8. Write a query to create a view that finds the salesman who has the customer with the highest order at least 3 times on a day.sql @@ -0,0 +1,9 @@ +/*8. Write a query to create a view that finds the salesman who has the customer with the highest order at least 3 times + on a day.*/ +CREATE VIEW incentive +AS SELECT DISTINCT salesman_id, name +FROM elitsalesman a +WHERE 3 <= + (SELECT COUNT (*) + FROM elitsalesman b + WHERE a.salesman_id = b.salesman_id); \ No newline at end of file diff --git a/sql/View/9. Write a query to create a view that shows all of the customers who have the highest grade.sql b/sql/View/9. Write a query to create a view that shows all of the customers who have the highest grade.sql new file mode 100644 index 0000000..d3a4afa --- /dev/null +++ b/sql/View/9. Write a query to create a view that shows all of the customers who have the highest grade.sql @@ -0,0 +1,7 @@ +/*9. Write a query to create a view that shows all of the customers who have the highest grade.*/ +CREATE VIEW highgrade + AS SELECT * + FROM customer + WHERE grade = + (SELECT MAX (grade) + FROM customer); \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find all those customers with all information whose names are ending with the letter 'n'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find all those customers with all information whose names are ending with the letter 'n'.sql new file mode 100644 index 0000000..10efe3e --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find all those customers with all information whose names are ending with the letter 'n'.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find all those customers with all information whose names are ending with the letter 'n'.*/ +SELECT * +FROM customer +WHERE cust_name LIKE '%n'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find that customer with all information who does not get any grade except NULL.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find that customer with all information who does not get any grade except NULL.sql new file mode 100644 index 0000000..3495d1a --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find that customer with all information who does not get any grade except NULL.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find that customer with all information who does not get any grade except NULL.*/ +SELECT * +FROM customer +WHERE grade IS NULL; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find that customer with all information who gets a grade except NULL value.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find that customer with all information who gets a grade except NULL value.sql new file mode 100644 index 0000000..2d29148 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find that customer with all information who gets a grade except NULL value.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find that customer with all information who gets a grade except NULL value.*/ +SELECT * +FROM customer +WHERE grade IS NOT NULL; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find that customers whose name begin with the letter 'B'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find that customers whose name begin with the letter 'B'.sql new file mode 100644 index 0000000..e1694b7 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find that customers whose name begin with the letter 'B'.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find that customers whose name begin with the letter 'B'.*/ +SELECT * +FROM customer +WHERE cust_name LIKE 'B%'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the character ( % ) in its column 'col1'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the character ( % ) in its column 'col1'.sql new file mode 100644 index 0000000..a641eed --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the character ( % ) in its column 'col1'.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find those rows from the table testtable which contain the character ( % ) in its column 'col1'.*/ +SELECT * +FROM testtable +WHERE coll LIKE '%/%%' ESCAPE'/'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the escape character in its column 'col1'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the escape character in its column 'col1'.sql new file mode 100644 index 0000000..3a95bba --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the escape character in its column 'col1'.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find those rows from the table testtable which contain the escape + character ( / ) in its column 'col1'. */ +SELECT * +FROM testtable +WHERE coll LIKE '%//%' ESCAPE '/'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the escape character underscore ( _ ) in its column 'col1'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the escape character underscore ( _ ) in its column 'col1'.sql new file mode 100644 index 0000000..a5dc164 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the escape character underscore ( _ ) in its column 'col1'.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find those rows from the table testtable which +contain the escape character underscore ( _ ) in its column 'col1'.*/ +SELECT * +FROM testtable +WHERE coll LIKE '%/_%' ESCAPE '/'; diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the string in its column 'col1'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the string in its column 'col1'.sql new file mode 100644 index 0000000..bab0616 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which contain the string in its column 'col1'.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find those rows from the table testtable which contain the string ( _/ ) in its column 'col1'.*/ +SELECT * +FROM testtable +WHERE coll LIKE '%/_//%' ESCAPE '/'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the character ( % ) in its column 'col1'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the character ( % ) in its column 'col1'.sql new file mode 100644 index 0000000..f42c50f --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the character ( % ) in its column 'col1'.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find those rows from the table testtable which does not contain the +character ( % ) in its column 'col1'.*/ +SELECT * +FROM testtable +WHERE coll NOT LIKE '%/%%' ESCAPE'/'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the character underscore ( _ ) in its column 'col1'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the character underscore ( _ ) in its column 'col1'.sql new file mode 100644 index 0000000..f249272 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the character underscore ( _ ) in its column 'col1'.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find those rows from the table testtable which does not +contain the character underscore ( _ ) in its column 'col1'.*/ + SELECT * + FROM testtable + WHERE coll NOT LIKE '%/_%' ESCAPE '/'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the escape character in its column 'col1'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the escape character in its column 'col1'.sql new file mode 100644 index 0000000..045bcdf --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the escape character in its column 'col1'.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find those rows from the table testtable which does not contain the escape +character ( / ) in its column 'col1'.*/ +SELECT * +FROM testtable +WHERE coll NOT LIKE '%//%' ESCAPE '/'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the string in its column 'col1'..sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the string in its column 'col1'..sql new file mode 100644 index 0000000..e69de29 diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the string in its column 'col1'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the string in its column 'col1'.sql new file mode 100644 index 0000000..bbb8a8f --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those rows from the table testtable which does not contain the string in its column 'col1'.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find those rows from the table testtable which does not contain the + string ( _/ ) in its column 'col1'. */ +SELECT * +FROM testtable +WHERE coll NOT LIKE '%/_//%' ESCAPE '/'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information who come from the city either Paris or Rome.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information who come from the city either Paris or Rome.sql new file mode 100644 index 0000000..af85962 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information who come from the city either Paris or Rome.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find those salesmen with all information who come from the city either Paris or Rome. */ +SELECT * +FROM salesman +WHERE city = 'Paris' OR city = 'Rome'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information who get the commission within a range of 0.12 and 0.14.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information who get the commission within a range of 0.12 and 0.14.sql new file mode 100644 index 0000000..4ff50c1 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information who get the commission within a range of 0.12 and 0.14.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find those salesmen with all information who get the commission within a range of 0.12 and 0.14. */ +SELECT * +FROM salesman +WHERE commission BETWEEN 0.12 AND 0.14; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information whose name containing the 1st character is 'N' and the 4th character is 'l'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information whose name containing the 1st character is 'N' and the 4th character is 'l'.sql new file mode 100644 index 0000000..b2cdd67 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all information whose name containing the 1st character is 'N' and the 4th character is 'l'.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find those salesmen with all information whose name containing the 1st character is +'N' and the 4th character is 'l' and rests may be any character.*/ +SELECT * +FROM salesman +WHERE name LIKE 'N__l%'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all other information and name started with any latter 'A' and 'L'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all other information and name started with any latter 'A' and 'L'.sql new file mode 100644 index 0000000..6be7bb5 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all other information and name started with any latter 'A' and 'L'.sql @@ -0,0 +1,4 @@ +/*Write a SQL statement to find those salesmen with all other information and name started with any latter 'A' and 'L'. */ +SELECT * +FROM salesman +WHERE name BETWEEN 'A' and 'L'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all other information and name started with other than any latter within 'A' and 'L'.sql b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all other information and name started with other than any latter within 'A' and 'L'.sql new file mode 100644 index 0000000..1d9f4ed --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a SQL statement to find those salesmen with all other information and name started with other than any latter within 'A' and 'L'.sql @@ -0,0 +1,5 @@ +/*Write a SQL statement to find those salesmen with all other information +and name started with other than any latter within 'A' and 'L'.*/ +SELECT * +FROM salesman +WHERE name NOT BETWEEN 'A' and 'L'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a query in SQL to display all the data of employees whose last name begins with an 'D'.sql b/sql/WildcardSpecialOperators/Write a query in SQL to display all the data of employees whose last name begins with an 'D'.sql new file mode 100644 index 0000000..987bdf7 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a query in SQL to display all the data of employees whose last name begins with an 'D'.sql @@ -0,0 +1,4 @@ +/*Write a query in SQL to display all the data of employees whose last name begins with an 'D'.*/ +SELECT * + FROM emp_details + WHERE emp_lname LIKE 'D%'; \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a query to filter those salesmen with all information who comes from any of the cities Paris and Rome.sql b/sql/WildcardSpecialOperators/Write a query to filter those salesmen with all information who comes from any of the cities Paris and Rome.sql new file mode 100644 index 0000000..6b30dec --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a query to filter those salesmen with all information who comes from any of the cities Paris and Rome.sql @@ -0,0 +1,4 @@ +/*Write a query to filter those salesmen with all information who comes from any of the cities Paris and Rome.*/ +SELECT * +FROM salesman +WHERE city IN('Paris','Rome'); \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a query to filter those salesmen with all information who likes to leave other cities than Paris and Rome.sql b/sql/WildcardSpecialOperators/Write a query to filter those salesmen with all information who likes to leave other cities than Paris and Rome.sql new file mode 100644 index 0000000..f844d5d --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a query to filter those salesmen with all information who likes to leave other cities than Paris and Rome.sql @@ -0,0 +1,4 @@ +/*Write a query to filter those salesmen with all information who likes to leave other cities than Paris and Rome.*/ +SELECT * +FROM salesman +WHERE city NOT IN('Paris','Rome'); \ No newline at end of file diff --git a/sql/WildcardSpecialOperators/Write a query to sort out those customers with all information whose ID value is within any of 3007, 3008 and 3009.sql b/sql/WildcardSpecialOperators/Write a query to sort out those customers with all information whose ID value is within any of 3007, 3008 and 3009.sql new file mode 100644 index 0000000..b043c42 --- /dev/null +++ b/sql/WildcardSpecialOperators/Write a query to sort out those customers with all information whose ID value is within any of 3007, 3008 and 3009.sql @@ -0,0 +1,4 @@ +/*Write a query to sort out those customers with all information whose ID value is within any of 3007, 3008 and 3009.*/ +SELECT * +FROM customer +WHERE customer_id IN (3007,3008,3009); \ No newline at end of file