You are on page 1of 6

1. Show me the employee IDs and hire dates for all employees who were hired before '1995-01-01'.

select employeeid,hiredate from "alanparadise/nw"."employees"


where hiredate <'1995-01-01'

2. Show me the birth dates and hire dates for all employees who were born before '1960-01-01'.

select birthdate ,hiredate from "alanparadise/nw"."employees"


where birthdate  <'1960-01-01'

3. Provide me a list of all employees who live in the USA, have a salary greater than $50,000, and were
born before January 1st, 1970.
4. Show me the employee IDs and hire dates of all employees who were hired after Nancy

SELECT employeeid, hiredate FROM "alanparadise/nw"."employees"


WHERE hiredate > (
   SELECT hiredate FROM "alanparadise/nw"."employees"
   WHERE firstname = 'Nancy');

5. Select all columns where the order date is not equal to '1996-07-04'.

select * from "alanparadise/nw"."orders"


where orderdate<>'1996-07-04';

6. Select all columns products table where the price is greater than 100 and the category is not
'Beverages'.

7. Select the first name, last name, and title columns where the hire date is not in ('1992-08-14', '1994-05-
01').

select firstname, lastname,title


from "alanparadise/nw"."employees"
where hiredate  not in ('1992-08-14', '1994-05-01');

8. Select all columns from the orders table where the required date is between '1996-08-01' and '1996-08-
31' and the ship country is not 'USA'.

select *from "alanparadise/nw"."orders"


where requireddate between'1996-08-01' and '1996-08-31' and shipcountry !='USA'
9. Select the product name, unit price, and supplier ID columns from the products table where the supplier
ID is not 1, 3, 5.

select productname, unitprice, supplierid  from "alanparadise/nw"."products"


where supplierid not in(1,3,5)

10. Provide me a list of all employees who were hired after '1996-01-01'.

select *from "alanparadise/nw"."employees"


where hiredate > '1996-01-01'

11. Give me the first and last names of all employees who do not have a title.

select firstname, lastname from "alanparadise/nw"."employees"


where title <> 'Sales Representative'

12. Provide me a list of all employees who live in the USA and have a last name that begins with 'S'.

select* from "alanparadise/nw"."employees"


where country='USA'and lastname like 'D%'

13. Show me the employee IDs and salaries of all employees who earn between $40,000 and $60,000 per
year and have a hire date before January 1st, 1995.

14. Provide me a list of all employees who have a last name starting with 'S' and whose birth year is
between 1950 and 1960.
select* from "alanparadise/nw"."employees"
where(birthdate >='1950-1-1' and birthdate <='1960-1-1' )and lastname like 'F%'

15. Show me the employee IDs and titles of all employees who have a title that contains the word
"Manager" and were hired after January 1st, 1990.

select employeeid,title from "alanparadise/nw"."employees"


where title='Sales Manager'  and hiredate>'1990-1-1'

16. Provide me a list of all employees who live in the USA, have a salary greater than $50,000, and were
born before January 1st, 1970.
17. Show me the employee IDs and hire dates of all employ who were hired after Nancy Davolio but
before Andrew Fuller.
18. Show me the employee IDs and salaries of all who earn between $40,000 and $60,000 per year and
were born between January 1st, 1950 and December 31st, 1960, and are not currently managers.
19. Provide me a list of all employees who have a first name that contains the letter 'e' and a last name that
contains the letter 'o', and were hired after January 1st, 1995.

SELECT * FROM "alanparadise/nw"."employees"


WHERE firstname like '%e%' and lastname like '%o%' and hiredate >'1995-1-1'
 

20. Show me the employee IDs and birth dates of all employees who were born in the same year as their
hire date.
21. Provide me a list of all employees who live in the USA or the UK, have a salary greater than $50,000,
and have been with the company for more than 10 years.
22. Show me the employee IDs and salaries of all employees who have a salary that is a multiple of 1000
and were hired before January 1st, 1995.
23. Provide me a list of all employees whose salary is greater than $50,000 and work in either the Sales or
Marketing department, and were hired between January 1st, 2019, and December 31st, 2021.
24. Provide me a list of all employees who either live in California, USA or British Columbia or Alberta,
Canada.

SELECT * FROM "alanparadise/nw"."employees"


WHERE country in ('London','UK','seattle','Tacoma','USA')

25. Provide me a list of all employees whose hire date plus five years is greater than the current date and
whose annual salary is less than $70,000.
26. This command selects employees whose job title contains the word "manager", their salary is between
$60,000 and $80,000, and they do not work in either the IT or HR department.
27. This command selects employees whose first name is John, Jane, or Peter, and their last name ends
with "son" or "er".

SELECT * FROM "alanparadise/nw"."employees"


WHERE firstname in ('John','Jane','Peter') and lastname like '%son' or lastname
like '%er'
 

PRACTICING PATTERN MATCHING FOR FIXED LENGTH


1. Which employees have a last name that is exactly 5 characters long and starts with the letter
'S'?

SELECT * FROM "alanparadise/nw"."employees"


WHERE firstname like 'S____';

2. What products have a name that starts with the letter 'A' and ends with exactly 4 characters,
including a letter 'C' as the third character?

SELeCT * FROM "alanparadise/nw"."products"


where productname like'A__C_';

3. Who are the customers with a phone number that starts with the area code '415' and ends with
exactly 4 digits?

SELeCT * FROM "alanparadise/nw"."customers"


where phone like '415____';

4. What orders have a shipping address that contains the word 'Street' followed by a space and
then exactly 3 characters?

SELeCT * FROM "alanparadise/nw"."orders"


where shipaddress like 'Street ___' ;
5. Which employees have a first name that starts with the letter 'J' and ends with exactly 6
characters, including an 'n' as the third character and an 'e' as the sixth character?

SELECT * FROM "alanparadise/nw"."employees"


WHERE firstname like 'J__n__e';

ORDER BY and LIMIT:

Select all employees from the USA and order them by first name in ascending order:

SELCT * FROM "alanparadise/nw"."employees"


where country ='USA' order by firstname;

Select all employees with the title "Manager" and order them by birthdate in descending order:

SELeCT * FROM "alanparadise/nw"."employees"


where title ='Sales Manager' order by birthdate;

Select all employees hired between January 1st, 2000 and December 31st, 2010, and order them by hire date in
ascending order:

SELECT * FROM "alanparadise/nw"."employees"


where hiredate between '2000-1-1' and '2010-31-10'
order by hiredate;

Select all employees from the city "Seattle" and order them by home phone number in ascending order:

SELECT * FROM "alanparadise/nw"."employees"


where city ='Seattle' order by homephone;

Questions that involve using CONCAT, AGE, and computational columns

Show a list of all employees' first and last names along with their ages (as of the current date).

SELeCT * FROM "alanparadise/nw"."employees", age('2023-3-18', birthdate)

Create a new column in the orders table called total_price that multiplies the unitprice and quantity columns.

select  * , (unitprice* quantity) AS "total_price" FROM


"alanparadise/nw"."orderdetails" ;
Calculate the age of each employee.

SELECT * FROM "alanparadise/nw"."employees" ,age(birthdate)

You might also like