Retrieve the names of users whose age is greater than 30.
SELECT name FROM users WHERE age > 30;
Day 2: Data Manipulation
Topics:
Updating records with UPDATE statement
Deleting records with DELETE statement
Limiting and pagination with LIMIT and OFFSET
Aggregation functions: COUNT, SUM, AVG, MIN, MAX
Grouping data with GROUP BY
Assignments:
Update the age of the user with id 2 to 35.
UPDATE users SET age = 35 WHERE id = 2;
Delete the user with id 4 from the “users” table.
DELETE FROM users WHERE id = 4;
Retrieve the first 3 records from the “users” table.
SELECT * FROM users LIMIT 3;
Retrieve the total number of users in the “users” table.
SELECT COUNT(*) FROM users;
Retrieve the average age of users.
SELECT AVG(age) FROM users;
Day 3: Filtering and Sorting
Topics:
Using WHERE clause for conditional filtering
Using comparison operators: =, <>, <, >, <=, >=
Using logical operators: AND, OR, NOT
Sorting data with ORDER BY clause
Sorting in ascending and descending order
Assignments:
Retrieve the names of users whose city is ‘Mumbai’.
SELECT name FROM users WHERE city = 'Mumbai';
Retrieve the names of users whose age is between 25 and 35.
SELECT name FROM users WHERE age BETWEEN 25 AND 35;
Retrieve the names of users whose city is not ‘Delhi’.
SELECT name FROM users WHERE city <> 'Delhi';
Retrieve all records from the “users” table sorted by age in ascending order.
SELECT * FROM users ORDER BY age ASC;
Retrieve all records from the “users” table sorted by name in descending order.
SELECT * FROM users ORDER BY name DESC;
Day 4: Data Aggregation and Functions
Topics:
Using aggregate functions: COUNT, SUM, AVG, MIN, MAX
Working with NULL values: IS NULL, IS NOT NULL
Using mathematical functions: ROUND, CEILING, FLOOR
String functions: CONCAT, UPPER, LOWER, LENGTH
Date functions: NOW, DATE_FORMAT, DATE_ADD, DATE_SUB
Assignments:
Retrieve the total number of users in the “users” table.
SELECT COUNT(*) FROM users;
Retrieve the sum of ages of all users.
SELECT SUM(age) FROM users;
Retrieve the average age of users excluding NULL values.
SELECT AVG(age) FROM users WHERE age IS NOT NULL;
Retrieve the concatenated names and cities of all users.
SELECT CONCAT(name, ', ', city) AS info FROM users;
Retrieve the current date and time.
SELECT NOW();
Day 5: Grouping and Filtering with HAVING Clause
Topics:
Grouping data with GROUP BY clause
Filtering grouped data with HAVING clause
Using aggregate functions with GROUP BY
Using multiple columns in GROUP BY
Combining GROUP BY, HAVING, and ORDER BY
Assignments:
Retrieve the names and ages of users grouped by city.
SELECT city, GROUP_CONCAT(name) AS names, GROUP_CONCAT(age) AS ages FROM users GROUP BY city;
Retrieve the cities with more than 2 users.
SELECT city FROM users GROUP BY city HAVING COUNT(*) > 2;
Retrieve the average age of users in each city.
SELECT city, AVG(age) AS average_age FROM users GROUP BY city;
Retrieve the cities with the highest and lowest average age of users.
SELECT city, AVG(age) AS average_age FROM users GROUP BY city HAVING AVG(age) = (SELECT MAX(avg_age) FROM (SELECT AVG(age) AS avg_age FROM users GROUP BY city) AS temp) OR AVG(age) = (SELECT MIN(avg_age) FROM (SELECT AVG(age) AS avg_age FROM users GROUP BY city) AS temp);
Retrieve the cities with at least 1 user whose age is greater than 30, sorted by city name.
SELECT city FROM users WHERE age > 30 GROUP BY city ORDER BY city ASC;
Create a basic HTML document structure with a title and heading.
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Webpage</h1>
</body>
</html>
Write a paragraph describing your favorite hobby using appropriate HTML tags.
<!DOCTYPE html>
<html>
<head>
<title>My Hobbies</title>
</head>
<body>
<h2>My Favorite Hobby</h2>
<p>I enjoy playing the guitar in my free time. It's a great way to relax and express my creativity.</p>
</body>
</html>
Create an ordered list of your top 5 favorite movies.
Linking to external websites and internal sections
Inserting images in HTML
Image attributes and alternative text
Assignments:
Create a hyperlink that opens a new tab and leads to your favorite website.
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body>
<h1>Welcome to My Webpage</h1>
<a href="https://www.example.com" target="_blank">Visit Example.com</a>
</body>
</html>
Link an internal section within the same webpage using anchor tags.
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body>
<h1>Welcome to My Webpage</h1>
<a href="#about">Jump to About Section</a>
<h2 id="about">About</h2>
<p>This is the About section of my webpage.</p>
</body>
</html>
Insert an image of your favorite animal with appropriate alt text.
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body>
<h1>Welcome to My Webpage</h1>
<img src="animal.jpg" alt="A picture of my favorite animal">
</body>
</html>
Create a gallery of three images using HTML and appropriate attributes.
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
<style>
h1 {
color: blue;
font-size: 24px;
}
h2 {
color: green;
font-size: 20px;
}
</style>
</head>
<body>
<h1>Welcome to My Webpage</h1>
<h2>About Me</h2>
<!-- Rest of the content -->
</body>
</html>
Add a background color and padding to the paragraphs in your webpage using CSS.
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
<style>
p {
background-color: lightgray;
padding: 10px;
}
</style>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<!-- Rest of the content -->
</body>
</html>
Create a navigation bar using an unordered list and style it with CSS.
define("PI", 3.14);
echo "The value of PI is: " . PI;
Example 3: Variable scope (local and global):
$globalVariable = "I am a global variable";
function myFunction() {
$localVariable = "I am a local variable";
echo $localVariable;
echo $GLOBALS['globalVariable'];
}
myFunction();
$num1 = 10;
$num2 = 5;
var_dump($num1 == $num2); // Equal to
var_dump($num1 != $num2); // Not equal to
var_dump($num1 > $num2); // Greater than
var_dump($num1 < $num2); // Less than
var_dump($num1 >= $num2); // Greater than or equal to
var_dump($num1 <= $num
2); // Less than or equal to
$num = 10;
if ($num > 0) {
echo "The number is positive";
} else {
echo "The number is not positive";
}
Example 2: Switch case statement:
$day = "Monday";
switch ($day) {
case "Monday":
echo "Today is Monday";
break;
case "Tuesday":
echo "Today is Tuesday";
break;
default:
echo "Today is not Monday or Tuesday";
}
class Person {
public $name;
public $age;
public function sayHello() {
echo "Hello, my name is " . $this->name . " and I am " . $this->age . " years old.";
}
}
$person = new Person();
$person->name = "John";
$person->age = 25;
$person->sayHello();
Example 2: Constructors and property accessors:
class Person {
private $name;
private $age;
public function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
public function getName() {
return $this->name;
}
public function getAge() {
return $this->age;
}
}
$person = new Person("John", 25);
echo $person->getName(); // Output: John
echo $person->getAge(); // Output: 25
Example 3: Inheritance:
class Animal {
public function makeSound() {
echo "The animal makes a sound.";
}
}
class Dog extends Animal {
public function makeSound() {
echo "The dog barks.";
}
}
$dog = new Dog();
$dog->makeSound(); // Output: The dog barks.
Example
4: Static properties and methods:
class MathUtils {
public static $pi = 3.14159;
public static function square($num) {
return $num * $num;
}
}
echo MathUtils::$pi; // Output: 3.14159
echo MathUtils::square(5); // Output: 25
Example 5: Abstract classes and interfaces:
abstract class Animal {
abstract public function makeSound();
}
interface CanFly {
public function fly();
}
class Bird extends Animal implements CanFly {
public function makeSound() {
echo "The bird chirps.";
}
public function fly() {
echo "The bird is flying.";
}
}
$bird = new Bird();
$bird->makeSound(); // Output: The bird chirps.
$bird->fly(); // Output: The bird is flying.
Remember to replace “your_username”, “your_password”, and “your_database” with your actual MySQL credentials and database name. Additionally, ensure that PDO extension is enabled in your PHP configuration.
package main
import "fmt"
func main() {
var message string = "Hello, Go!"
fmt.Println(message)
const pi = 3.14159
fmt.Println(pi)
}
Data Types and Type Conversion:
package main
import "fmt"
func main() {
var age int = 25
fmt.Println(age)
var price float64 = 9.99
fmt.Println(price)
var isTrue bool = true
fmt.Println(isTrue)
var name string = "John"
fmt.Println(name)
// Type conversion
var num int = 42
var result float64 = float64(num)
fmt.Println(result)
}
Operators
package main
import "fmt"
func main() {
var a = 10
var b = 5
fmt.Println(a + b)
fmt.Println(a - b)
fmt.Println(a * b)
fmt.Println(a / b)
fmt.Println(a % b)
var isTrue = true
fmt.Println(!isTrue)
}
Control Structures: if-else and switch:
package main
import "fmt"
func main() {
var num = 5
if num > 0 {
fmt.Println("Number is positive")
} else if num < 0 {
fmt.Println("Number is negative")
} else {
fmt.Println("Number is zero")
}
var day = "Monday"
switch day {
case "Monday":
fmt.Println("It's Monday")
case "Tuesday":
fmt.Println("It's Tuesday")
default:
fmt.Println("It's another day")
}
}
Loops: for and range
package main
import "fmt"
func main() {
// For loop
for i := 1; i <= 5; i++ {
fmt.Println(i)
}
// Range loop
nums := []int{1, 2, 3, 4, 5}
for index, value := range nums {
fmt.Println(index, value)
}
}
Functions in Go
Simple Function:
package main
import "fmt"
func add(a, b int) int {
return a + b
}
func main() {
result := add(3, 5)
fmt.Println(result)
}
Function with Multiple Return Values:
package main
import "fmt"
func divide(a, b int) (int, int) {
quotient := a / b
remainder := a % b
return quotient, remainder
}
func main() {
q, r := divide(10, 3)
fmt.Println("Quotient:", q)
fmt.Println("Remainder:", r)
}
Variadic Function:
package main
import "fmt"
func sum(numbers ...int) int {
total := 0
for _, num := range numbers {
total += num
}
return total
}
func main() {
result := sum(1, 2, 3, 4, 5)
fmt.Println(result)
}
Anonymous Functions and Closures:
package main
import "fmt"
func main() {
add := func(a, b int) int {
return a + b
}
result := add(3, 5)
fmt.Println(result)
}
Recursion:
package main
import "fmt"
func factorial(n int) int {
if n == 0 {
return 1
}
return n * factorial(n-1)
}
func main() {
result := factorial(5)
fmt.Println(result)
}
package main
import "fmt"
func main() {
numbers := []int{1, 2, 3, 4, 5}
fmt.Println(numbers)
fmt.Println(numbers[1:4]) // Slicing a slice
numbers = append(numbers, 6) // Appending an element
fmt.Println(numbers)
numbers = append(numbers[:2], numbers[3:]...) // Removing an element
fmt.Println(numbers)
}
Maps:
package main
import "fmt"
func main() {
person := map[string]string{
"name": "John",
"age": "30",
"email": "john@example.com",
}
fmt.Println(person)
fmt.Println(person["name"])
person["city"] = "New York" // Adding a new key-value pair
fmt.Println(person)
delete(person, "age") // Removing a key-value pair
fmt.Println(person)
}
Iterating over Slices and Maps:
package main
import "fmt"
func main() {
numbers := []int{1, 2, 3, 4, 5}
for index, value := range numbers {
fmt.Println(index, value)
}
person := map[string]string{
"name": "John",
"age": "30",
"email": "john@example.com",
}
for key, value := range person {
fmt.Println(key, ":", value)
}
}
Structs and Methods in Go
Structs:
package main
import "fmt"
type Person struct {
name string
age int
address string
}
func main() {
person := Person{"John", 30, "New York"}
fmt.Println(person)
fmt.Println(person.name)
fmt.Println(person.age)
fmt.Println(person.address)
}
Certainly! Here are ten examples for each of the topics you mentioned:
BASICS
Basics: Example 1: Printing a message
print("Hello, World!")
Example 2: Arithmetic operations
a = 10
b = 5
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Modulo:", a % b)
Example 3: String concatenation
name = "Alice"
age = 25
print("My name is " + name + " and I am " + str(age) + " years old.")
Example 4: Using the input function
name = input("Enter your name: ")
print("Hello, " + name + "!")
Example 5: Conditional statements
num = int(input("Enter a number: "))
if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")
text = "Hello, World!"
print("Length:", len(text))
Example 9: Using the str() function
num = 42
text = "The answer is: " + str(num)
print(text)
Example 10: Importing and using modules
import math
radius = 5
area = math.pi * radius ** 2
print("Area of the circle:", area)
CONDITIONAL STATEMENTS IF ELSE
If-Else Statements: Example 1: Checking if a number is even or odd
num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")
Example 2: Checking if a year is a leap year
year = int(input("Enter a year: "))
if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):
print("The year is a leap year.")
else:
print("The year is not a leap year.")
Example 3: Determining the maximum of three numbers
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
max_num = max(num1, num2, num3)
print("The maximum number is:", max_num)
Example 4: Checking if a student passed or failed
score = float(input("Enter the student's score: "))
if score >= 60:
print("The student passed.")
else:
print("The student failed.")
Example 5
: Categorizing a number into different ranges
num = float(input("Enter a number: "))
if num < 0:
print("The number is negative.")
elif num >= 0 and num <= 10:
print("The number is between 0 and 10.")
elif num > 10 and num <= 20:
print("The number is between 10 and 20.")
else:
print("The number is greater than 20.")
Example 6: Checking if a person is eligible to vote
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote yet.")
Example 7: Checking if a number is positive, negative, or zero (alternative approach)
num = float(input("Enter a number: "))
if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")
Example 8: Checking if a character is a vowel or consonant
char = input("Enter a character: ").lower()
if char in ['a', 'e', 'i', 'o', 'u']:
print("The character is a vowel.")
else:
print("The character is a consonant.")
Example 9: Checking if a number is a multiple of another number
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if num1 % num2 == 0:
print(num1, "is a multiple of", num2)
else:
print(num1, "is not a multiple of", num2)
Example 10: Checking if a year is a leap year (alternative approach)
year = int(input("Enter a year: "))
if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):
print("The year is a leap year.")
else:
print("The year is not a leap year.")
For loop with range
Printing numbers from 0 to 9:
for i in range(10):
print(i)
Printing even numbers from 2 to 10:
for i in range(2, 11, 2):
print(i)
Calculating the sum of numbers from 1 to 100:
total = 0
for i in range(1, 101):
total += i
print("Sum:", total)
Printing numbers in reverse order from 9 to 0:
for i in range(9, -1, -1):
print(i)
Multiplying each number in the range by 2 and printing the result:
for i in range(10):
result = i * 2
print(result)
Printing the square of each number in the range from 1 to 5:
for i in range(1, 6):
square = i ** 2
print(square)
Printing numbers in increments of 5 from 0 to 50:
for i in range(0, 51, 5):
print(i)
Checking if a number is divisible by 3 in the range from 1 to 20:
for i in range(1, 21):
if i % 3 == 0:
print(i, "is divisible by 3")
Printing the ASCII value of each character in a string:
text = "Hello"
for char in text:
ascii_value = ord(char)
print(char, ":", ascii_value)
Repeating a specific action a certain number of times using range: