Micro Cheat Sheet
Micro Cheat Sheet
return self.stack[-1]
Cheatsheet 5: Python Cheatsheet 6: SQL
Sor ng Results (ORDER BY Clause)
else: SELECT * FROM Students ORDER BY Marks DESC;
return "Stack is empty"
Data Structures Basics and Queries 5. Aggregate Func ons
def is_empty(self): Func on Descrip on Example
(Stacks) return len(self.stack) == 0 1. SQL Overview
MAX()
Returns the SELECT MAX(Marks)
Structured Query Language (SQL): Used highest value FROM Students;
1. Introduc on to Stacks def size(self): to manage and query rela onal Returns the SELECT MIN(Marks)
databases. MIN()
Defini on: A stack is a linear data return len(self.stack) lowest value FROM Students;
Key SQL Categories:
structure following the LIFO principle Returns the SELECT AVG(Marks)
o DDL: Data Defini on Language AVG()
(Last In, First Out). # Example Usage average value FROM Students;
(e.g., CREATE, DROP, ALTER)
Applica ons: s = Stack() Returns the sum SELECT SUM(Marks)
o DML: Data Manipula on SUM()
o Undo opera ons s.push(10) of values FROM Students;
Language (e.g., SELECT, INSERT,
o Backtracking (e.g., browser s.push(20) UPDATE, DELETE) Returns the SELECT COUNT(*)
COUNT()
history) print(s.pop()) # Output: 20 number of rows FROM Students;
o Expression evalua on (e.g., print(s.peek()) # Output: 10 2. Common SQL Commands
pos ix, infix) Command Descrip on 6. Joining Tables
4. Opera ons on Stack (Push and Pop) Example: Inner Join
CREATE Creates a new table or database
SELECT Students.Name, Courses.CourseName
2. Stack Opera ons Push Opera on INSERT Adds new data to a table FROM Students
Opera on Descrip on 1. Add the item to the end of the list. SELECT Retrieves data from a table INNER JOIN Courses
Add an item to the top of the stack = [] ON Students.StudentID = Courses.StudentID;
UPDATE Modifies exis ng data in a table
push(item) stack.append(5) # Push 5 to stack
stack DELETE Removes data from a table Other Joins
Pop Opera on Type Descrip on
pop() Remove and return the top item DROP Deletes a table or database
1. Remove the last item added to the
View the top item without ALTER Modifies the structure of a table Returns matching rows from both
list. INNER JOIN
peek() tables
removing it item = stack.pop() # Pop from stack
3. Crea ng and Managing Tables Returns all rows from the le
is_empty() Check if the stack is empty LEFT JOIN
Create Table table
Return the number of items in Returns all rows from the right
size() CREATE TABLE Students (
the stack RIGHT JOIN
StudentID INT PRIMARY KEY, table
Name VARCHAR(50), FULL OUTER
Returns all rows from both tables
3. Implemen ng Stack Using a List Age INT, JOIN
Code Example Marks FLOAT
class Stack: ); 7. Inser ng, Upda ng, and Dele ng Data
def __init__(self): Modify Table (ALTER) Insert Data
Add a column: INSERT INTO Students (StudentID, Name, Age,
self.stack = []
ALTER TABLE Students ADD Address Marks)
VARCHAR(100); VALUES (1, 'Alice', 20, 85.5);
def push(self, item):
Drop a column: Update Data
self.stack.append(item) ALTER TABLE Students DROP COLUMN Address; UPDATE Students
Delete Table SET Marks = 90
def pop(self): DROP TABLE Students; WHERE StudentID = 1;
if not self.is_empty(): Delete Data
return self.stack.pop() 4. Querying Data (SELECT) DELETE FROM Students WHERE StudentID = 1;
else: Basic Syntax
return "Stack is empty" SELECT column1, column2 FROM TableName;
Example
SELECT Name, Marks FROM Students;
def peek(self):
Filtering Results (WHERE Clause)
if not self.is_empty():
SELECT * FROM Students WHERE Age > 18;
6. host="localhost",
Cheatsheet 7: 7. user="root", Cheatsheet 8: Switch
Connects devices in a LAN and uses MAC
addresses to forward data.
8. password="yourpassword", Broadcasts data to all connected devices in a
Advanced SQL and 9.
10. )
database="school"
Networking Concepts Hub
network.
Gateway Connects networks with different protocols.
Python-SQL
11.
cursor = conn.cursor() 1. Key Networking Concepts
12. Execute Queries: Term Defini on 5. Network Topologies
4. SQL Basics
DDL: CREATE, DROP, ALTER.
DML: SELECT, INSERT, UPDATE,
DELETE.