Python + SQL + Matplotlib Project
Contains: 10 SQL queries, 15 Python examples, 5 Matplotlib plots (with outputs)
Generated for user request
All students Query: SELECT * FROM students; Output (first 20 rows shown): id name
age grade 1 Asha 16 A 2 Rohit 17 B 3 Meera 16 A 4 Vikram
18 C 5 Sonal 17 B
Students with grade A Query: SELECT name, age FROM students WHERE grade='A'; Output
(first 20 rows shown): name age Asha 16 Meera 16
Average student age Query: SELECT AVG(age) as avg_age FROM students; Output (first 20
rows shown): avg_age 16.8
Employees in IT Query: SELECT name, salary FROM employees WHERE dept='IT' ORDER BY salary
DESC; Output (first 20 rows shown): name salary Geeta 62000 Priya 60000
Total payroll Query: SELECT SUM(salary) as total_payroll FROM employees; Output (first
20 rows shown): total_payroll 254000
Sales summary per product Query: SELECT product, SUM(qty) as total_qty, SUM(qty*price) as
revenue FROM sales GROUP BY product; Output (first 20 rows shown): product total_qty
revenue Mug 2 300.0 Notebook 8 166.0 Pen 30
65.0
Top selling product by qty Query: SELECT product FROM sales GROUP BY product ORDER BY
SUM(qty) DESC LIMIT 1; Output (first 20 rows shown): product Pen
Sales in Nov 2025 Query: SELECT * FROM sales WHERE sale_date BETWEEN '2025-11-01' AND
'2025-11-30'; Output (first 20 rows shown): id product qty price sale_date 1
Pen 10 2.5 2025-11-01 2 Notebook 5 20.0 2025-11-03 3 Mug 2 150.0
2025-11-05 4 Pen 20 2.0 2025-11-07 5 Notebook 3 22.0 2025-11-10
Join students & employees (cartesian example limited) Query: SELECT [Link] as student,
[Link] as employee FROM students s JOIN employees e ON [Link]=1 LIMIT 5; Output (first 20
rows shown): student employee Asha Raj Rohit Raj Meera Raj Vikram
Raj Sonal Raj
Employees with salary > 45000 Query: SELECT * FROM employees WHERE salary>45000; Output
(first 20 rows shown): id name dept salary 2 Priya IT 60000 4 Geeta IT
62000 5 Sunil Sales 47000
List comprehension (squares 1..10) Code: squares = [x*x for x in range(1,11)] squares
Output: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Fibonacci (first 8) Code: def fib(n): # returns first n fib numbers a,b=0,1
res=[] for _ in range(n): [Link](b) a,b=b,a+b return res
fib(8) Output: [1, 1, 2, 3, 5, 8, 13, 21]
Word frequency with Counter Code: from collections import Counter text='apple orange
apple banana apple orange' Counter([Link]()) Output: {'apple': 3, 'orange': 2,
'banana': 1}
Read CSV into DataFrame Code: import pandas as pd df = pd.read_csv('[Link]') df
Output: {'col1': [1, 2, 3], 'col2': ['a', 'b', 'c']}
Lambda + map doubling Code: nums = [1,2,3,4,5] double = list(map(lambda x: x*2, nums))
double Output: [2, 4, 6, 8, 10]
Filter even numbers 1..20 Code: nums = range(1,21) evens = list(filter(lambda x: x%2==0,
nums)) evens Output: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
JSON serialization Code: import json data = {'name':'Sumita','subject':'Python'}
[Link](data) Output: {"name": "Sumita", "subject": "Python"}
Simple class and method Code: class Person: def __init__(self,name,age):
[Link]=name; [Link]=age def greet(self): return f"Hi, I'm {[Link]} and
I'm {[Link]}" Person('Rishabh',25).greet() Output: Hi, I'm Rishabh and I'm 25
Exception handling (division by zero) Code: try: 1/0 except Exception as e:
str(e) Output: division by zero
Write and read a text file Code: with open('sample_txt.txt') as f: data=[Link]()
data Output: Hello world\nThis is a sample file.
Pandas groupby sum (sales qty) Code: [Link]('product').[Link]().to_dict() Output:
{'Mug': 2, 'Notebook': 8, 'Pen': 30}
Regex findall phone numbers Code: import re [Link](r'\d{3}-\d{3}-\d{4}', 'Call
123-456-7890 or 987-654-3210') Output: ['123-456-7890', '987-654-3210']
Datetime parsing & formatting Code: from datetime import datetime
[[Link](d,'%Y-%m-%d').strftime('%d %b %Y') for d in
['2025-11-01','2025-11-07']] Output: ['01 Nov 2025', '07 Nov 2025']
Set union & intersection Code: a=set([1,2,3,4]); b=set([3,4,5]);
{'union':list(a|b),'intersection':list(a&b)} Output: {'union': [1, 2, 3, 4, 5],
'intersection': [3, 4]}
List min/max/sort Code: nums=[5,2,9,4,7]
{'min':min(nums),'max':max(nums),'sorted':sorted(nums)} Output: {'min': 2, 'max': 9,
'sorted': [2, 4, 5, 7, 9]}
Line plot
Bar plot
Scatter
Histogram
Pie chart