### 5 SQL Queries That Popularly Used in Data Analysis

Here are five popular SQL queries frequently used in data analysis. 1. SELECT with Aggregations Summarize data by calculating aggregates like counts, sums, averages, etc. SELECT department, COUNT(*) as employee_count, AVG(salary) as average_salary FROM employees GROUP BY department; 2. JOIN Operations  Combine data from multiple tables based on a related column. SELECT e.employee_id, e.name, d.department_name FROM employees e JOIN departments d ON e.department_id = d.department_id; 3. WHERE Clause for Filtering Filter records based on specified conditions. SELECT * FROM sales WHERE sale_date BETWEEN '2024-01-01' AND '2024-12-31'   AND amount > 1000; 4. ORDER BY Clause for Sorting Sort results in ascending or descending order based on one or more columns. SELECT product_name, price FROM products ORDER BY price DESC; 5. GROUP BY with HAVING Clause Group records and apply conditions to the aggregated results. SELECT department, SUM(salary) as total_salaries FROM employ

# Python Set comprehension - How to Use it Read now

In python, Set does not allow duplicates, and  you can't modify an existing set with a comprehension. But using the Set comprehension you can create a new Set.

## Set Comprehension

In addition, the comprehension must result in a valid set.  Likewise Dictionary, a set does not allow entries of the same value.

If you try to add values to the set that are already there, it will replace the old one with the new one.

## Explained syntax

Set comprehensions using the {} syntax only exist in Python 3. Before that, you'll have to use the set() function to create and work with sets. You might guess, therefore, that one of the best uses of a set is to eliminate duplicates.

In fact, this is one of the most basic forms of set comprehension. Given a list, we can duplicate it as a list with a simple list comprehension like this:

## Details of logic

if we change the list comprehension to a set comprehension, we get the same result, but as a set. That means without duplicates.

list_copy = [x for x in original_list]

## Sample Set comprehension

my_list_with_dupes = [1,2,1,2,3,4,1,2,3,4,5,6,7,1,2,3]
my_set_without_dupes = {x for x in my_list_with_dupes}
print(my_set_without_dupes)

{1, 2, 3, 4, 5, 6, 7}

Related posts