Powered By Blogger

Tuesday, June 10, 2014

Some Useful Queries in Sql

-- Write a query to list the employees whose salaries are within the range of 5000 and 10000
   SELECT * FROM EMP WHERE SAL BETWEEN 5000 AND 10000

-- Write a query to list the employees who have joined in the month of March’99
   SELECT * FROM EMP WHERE MONTHNAME(HIREDATE)='March' AND YEAR(HIREDATE)=1999

-- Write a query to list the employees whose salaries are not within the range of 10000 and 13000
   SELECT * FROM EMP WHERE SAL NOT BETWEEN 10000 AND 13000

-- Write a query who are getting 1000, 2000, 3000
   SELECT * FROM EMP WHERE SAL IN (1000,2000,3000)

-- Query to list all employees except who are joined on 11- Sep-2001, 31-Mar-2001 and 30-Jan-2001(It also compares time).
   SELECT * FROM EMP WHERE HIREDATE NOT IN ( DATE('09-11-2001'),
                                          DATE('03-31-2001'),DATE('01-30-2001') )

No comments:

Post a Comment