-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy path9.where
More file actions
44 lines (32 loc) · 1.59 KB
/
Copy path9.where
File metadata and controls
44 lines (32 loc) · 1.59 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
My complete SQL Masterclass Notes in Tanglish is now live! Covers 30+ topics with syntax, examples, and step-by-step explanations.
Perfect for both beginners and professionals to master SQL easily. Check it out here 👉 https://topmate.io/dataengineering/1697791
====================================================================================
Let's consider an Uber use case where we have a table rides that contains information about each ride, such as ride_id, driver_id, rider_id,
pickup_location, dropoff_location, ride_date, and fare.
Query: Using WHERE to Filter Data
The WHERE clause is used to filter records based on a condition. For example, if you want to find all the rides where the fare is greater
than 500
Code
CREATE TABLE rides (
ride_id INT PRIMARY KEY,
driver_id INT,
rider_id INT,
pickup_location VARCHAR(100),
dropoff_location VARCHAR(100),
ride_date DATETIME,
fare DECIMAL(10, 2)
);
INSERT INTO rides (ride_id, driver_id, rider_id, pickup_location, dropoff_location, ride_date, fare)
VALUES
(1, 101, 201, 'Chennai', 'Coimbatore', '2024-12-29 08:00:00', 500.00),
(2, 102, 202, 'Bangalore', 'Hyderabad', '2024-12-29 10:00:00', 800.00),
(3, 103, 203, 'Chennai', 'Madurai', '2024-12-29 12:00:00', 400.00),
(4, 104, 204, 'Coimbatore', 'Chennai', '2024-12-29 14:00:00', 600.00),
(5, 101, 205, 'Bangalore', 'Coimbatore', '2024-12-29 16:00:00', 700.00);
SELECT ride_id, driver_id, rider_id, pickup_location, dropoff_location, ride_date, fare
FROM rides
WHERE fare > 500;
select * from rides
where
fare > '500' and dropoff_location ='Chennai'
order by fare ;