-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20_Operators.sql
More file actions
53 lines (35 loc) · 1.54 KB
/
20_Operators.sql
File metadata and controls
53 lines (35 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
USE college;
-- 1. Arithmetic Operators
-- | Operator | Meaning | Example |
-- | -------- | ------------------- | ------------------ |
-- | `+` | Addition | `salary + 5000` |
-- | `-` | Subtraction | `salary - 2000` |
-- | `*` | Multiplication | `price * quantity` |
-- | `/` | Division | `total / 2` |
-- | `%` | Modulus (remainder) | `marks % 2` |
SELECT student_id, name, age+1 AS details FROM students;
-- 2. Comparison Operators
-- | Operator | Meaning |
-- | ------------ | --------------------- |
-- | `=` | Equal |
-- | `!=` or `<>` | Not equal |
-- | `>` | Greater than |
-- | `<` | Less than |
-- | `>=` | Greater than or equal |
-- | `<=` | Less than or equal |
SELECT * FROM students WHERE age >= 21;
-- 3. Logical Operators
-- | Operator | Meaning |
-- | -------- | ------------------------------ |
-- | `AND` | Both conditions must be true |
-- | `OR` | At least one condition is true |
-- | `NOT` | Reverses the condition |
SELECT * FROM students WHERE age >= 20 AND city = "Hyderabad";
SELECT name FROM students WHERE age >= 22 OR city = "Mumbai"
-- 4. BETWEEN Operator
SELECT * FROM students WHERE age BETWEEN 22 AND 30;
-- 5. IN Operator
SELECT * FROM students
WHERE city IN ('Chennai', 'Mumbai', 'Delhi');
-- 6. IS NULL / IS NOT NULL
SELECT * FROM students WHERE email IS NULL;