You are on page 1of 4

A DEPARTMENTS table contains DEP_NAME, and DEPT_ID_DEP columns and an EMPLOYEES table

contains columns called F_NAME and DEP_ID. We want to retrieve the Department Name for each
Employee. Which of the following queries will correctly accomplish this?

SELECT F_NAME, DEP_NAME FROM EMPLOYEES, DEPARTMENTS WHERE DEPT_ID_DEP =


DEP_ID

You are writing a query that will give you the total cost to the Pet Rescue organization of rescuing
animals. The cost of each rescue is stored in the Cost column. You want the result column to be called
“Total_Cost”. Which of the following SQL queries is correct?

SELECT SUM(Cost) AS Total_Cost FROM PetRescue

Which of the following will retrieve the LOWEST value of SALARY in a table called EMPLOYEES?

SELECT MIN(SALARY) FROM EMPLOYEES

Question 2
Which of the following queries will return the first name of the employee who earns the highest
salary?

SELECT FIRST_NAME FROM EMPLOYEES WHERE SALARY =

( SELECT MAX(SALARY) FROM EMPLOYEES )

Which of the following queries will return the data for employees who belong to the department with
the highest value of department ID

SELECT * FROM EMPLOYEES WHERE DEP_ID =

( SELECT MAX(DEPT_ID_DEP) FROM DEPARTMENTS )

Congratulations! You have completed this lesson. At this point in the course, you know:

 You can access a database from a language like Python by using the appropriate API.
Examples include ibm_db API for IBM DB2, psycopg2 for ProstgreSQL, and dblib API
for SQL Server.
 DB-API is Python's standard API for accessing relational databases. It allows you to
write a single program that works with multiple kinds of relational databases instead of
writing a separate program for each one.
 The DB_API connect constructor creates a connection to the database and returns a
Connection Object, which is then used by the various connection methods.
 The connection methods are: The cursor() method, which returns a new cursor object
using the connection. The commit() method, which is used to commit any pending
transaction to the database. The rollback() method, which causes the database to roll-
back to the start of any pending transaction. The close() method, which is used to close a
database connection.
 You can use SQL Magic commands to execute queries more easily from Jupyter
Notebooks. Magic commands have the general format %sql select * from tablename.
Cell magics start with a double %% (percent) sign and apply to the entire cell. Line
magics start with a single % (percent) sign and apply to a particular line in a cell.

 You can use Data Manipulation Language (DML) statements to read and modify data. 


 The search condition of the WHERE clause uses a predicate to refine the search. 
 COUNT, DISTINCT, and LIMIT are expressions that are used with SELECT statements

 INSERT, UPDATE, and DELETE are DML statements for populating and changing
tables.

Select

Employeeid,

Firstname,

Last,

City,

Case city

When ‘calgary’ then ‘calgary’ onehot encoding gibi

Else ‘other’

End calgary

From y
Select x Case

When x <2 then ‘smal’

When x >2 and x<5 then ‘medium’

When x>=5 then ‘large’

Else ‘other’

End bytes

From y

Create view my_view

As

Select a.b,

c.d,

e.f

from xlv c

innerjoin hghgh a ON c.d=a.b

innerjoin sdasd e ON a.b=e.f

UPDATE Alter tab le alter col set datatype

SET X =’A’

Where

In parantez içinde
Select X, count(x9 as “y”, AVG(salary) as “m” from a

Group by x

Having count(x) < 4

Order by m

Select x, y,

(Select avg(y) from a ) as avg_sal from a

You might also like