0% found this document useful (0 votes)
3 views4 pages

Styled SQL Python Interview Questions

The document contains a collection of SQL and Python interview questions along with their answers. It covers various SQL concepts such as SELECT, WHERE, JOINs, and aggregate functions, as well as Python topics like list comprehensions, lambda functions, and error handling. Each question is paired with a corresponding code example to illustrate the concepts effectively.

Uploaded by

noroozi.davood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Styled SQL Python Interview Questions

The document contains a collection of SQL and Python interview questions along with their answers. It covers various SQL concepts such as SELECT, WHERE, JOINs, and aggregate functions, as well as Python topics like list comprehensions, lambda functions, and error handling. Each question is paired with a corresponding code example to illustrate the concepts effectively.

Uploaded by

noroozi.davood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL & Python Interview Questions and Answers

SQL Interview Questions & Answers

1. Basic SELECT

Question: Write a SQL query to get all records from the 'employees' table.

SELECT * FROM employees;

2. WHERE Clause

Question: Get all customers from 'customers' table where country is 'USA'.

SELECT * FROM customers WHERE country = 'USA';

3. ORDER BY

Question: Retrieve all products ordered by price descending.

SELECT * FROM products ORDER BY price DESC;

4. GROUP BY and COUNT

Question: Count the number of orders per customer.

SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id;

5. HAVING

Question: Get products with more than 10 sales.

SELECT product_id, COUNT(*) AS total_sales FROM sales GROUP BY product_id HAVING


COUNT(*) > 10;

6. INNER JOIN

Question: List customers with their orders.

SELECT c.name, o.order_id FROM customers c INNER JOIN orders o ON c.customer_id =


o.customer_id;

7. LEFT JOIN

Question: List all customers and their orders, if any.

SELECT c.name, o.order_id FROM customers c LEFT JOIN orders o ON c.customer_id =


o.customer_id;
SQL & Python Interview Questions and Answers

8. Subquery

Question: Find products that have never been ordered.

SELECT * FROM products WHERE product_id NOT IN (SELECT product_id FROM orders);

9. UNION

Question: Combine customer and supplier emails.

SELECT email FROM customers UNION SELECT email FROM suppliers;

10. CASE WHEN

Question: Mark orders as 'High' if amount > 1000, else 'Low'.

SELECT order_id, amount, CASE WHEN amount > 1000 THEN 'High' ELSE 'Low' END AS
order_priority FROM orders;
SQL & Python Interview Questions and Answers

Python Interview Questions & Answers

1. List Comprehension

Question: Create a list of squares from 1 to 10.

squares = [x**2 for x in range(1, 11)]

2. Dictionary Comprehension

Question: Map numbers to their squares from 1 to 5.

squares_dict = {x: x**2 for x in range(1, 6)}

3. Lambda Function

Question: Write a lambda to add 10 to a number.

add_ten = lambda x: x + 10

4. Filter Function

Question: Filter even numbers from a list.

evens = list(filter(lambda x: x % 2 == 0, [1, 2, 3, 4, 5]))

5. Map Function

Question: Double each number in a list.

doubled = list(map(lambda x: x * 2, [1, 2, 3]))

6. Reduce Function

Question: Compute factorial using reduce.

from functools import reduce


factorial = reduce(lambda x, y: x * y, range(1, 6))

7. Try-Except

Question: Handle division by zero.

try:
x = 1 / 0
except ZeroDivisionError:
SQL & Python Interview Questions and Answers

print('Cannot divide by zero')

8. Class with __str__

Question: Create a class with a string representation.

class Person:
def __init__(self, name):
self.name = name
def __str__(self):
return f'Person: {self.name}'

9. Read File

Question: Read a file and print its contents.

with open('file.txt', 'r') as f:


print(f.read())

10. Decorator

Question: Write a simple decorator to log function calls.

def log(func):
def wrapper(*args, **kwargs):
print(f'Calling {func.__name__}')
return func(*args, **kwargs)
return wrapper

You might also like