SQL Flashcards

1
Q

What is a regional database

A

DB that organises info into one or more tables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name 2 ways to handle duplicate data points in an SQL query?

A

1) use the DISTINCT keyword
2) DELETE duplicate rows using ROWID with the MAX or MIN function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give an example of how you would use DISTINCT

A

SELECT DISTINCT Name, ADDRESS
FROM CUSTOMERS
ORDER BY Name;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give an example of how you would delete duplicates using ROWID

A

DELETE FROM Employee
WHERE ROWID NOT IN (
SELECT MAX(ROWID)
FROM Employee
GROUP BY Name, ADDRESS
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does Data aggregation involve ?

A

involves using aggregate functions like SUM(), AVG(), COUNT(), MIN(), and MAX()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s an example of data aggregation

A

SELECT department,
SUM(salary) AS total_salary,
AVG(salary) AS average_salary,
COUNT(*) AS employee_count
FROM employees
GROUP BY department;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s an example of data aggregation

A

SELECT department,
SUM(salary) AS total_salary,
AVG(salary) AS average_salary,
COUNT(*) AS employee_count
FROM employees
GROUP BY department;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Name 2 ways to handle missing data in SQL

A

1) COALESCE function
2) CASE statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s a COALESCE function and give an example of it.

A

It returns the first non-null value in the list

SELECT id, COALESCE(salary, 0) AS salary FROM employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are CASE statements and give an example of it.

A

They’re used handle missing values conditionally.

SELECT id,
CASE
WHEN salary IS NULL THEN 0
ELSE salary
END AS salary
FROM employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s is the ROLLUP Operator?

A

= an extension of the GROUP BY clause

It can be used to create subtotals and a grand total.

SELECT
department,
product,
SUM(sales) AS total_sales
FROM sales_data
GROUP BY ROLLUP(department, product);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you rank data in SQL?

A

Data engineers commonly rank values based on parameters such as sales and profit

SELECT
id,
sales,
RANK() OVER (ORDER BY sales DESC) AS rank
FROM bill;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are Common Table Expressions (CTEs) in SQL?

A

CTEs are used to simplify complex joins and run subqueries. They help make SQL queries more readable and maintainable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly