I have 1 Lakhs rows Random data of Ola Ride
Step I'm following here
- Data Cleaning
- Remove Duplicate
Data Tab on Ribon ---> - Trim Whitespace
Sabhi me nhi aa rha ab

- Import CSV File, go to Schema and Then table data import wizard
- Now Solving Problems One by One
- First Question is: #Retrieve all successful bookings from data:
Ans:
1️⃣ Database Creation
Explanation:
-
CREATE DATABASE Ola;→ नया database Ola बनाता है। -
USE Ola;→ अब जो भी commands देंगे, वो Ola database में apply होंगे।
2️⃣ Retrieve Successful Bookings Using View
Step-by-Step Explanation:
-
CREATE VIEW Successful_Bookings AS
-
यह command एक View बनाता है।
-
View: एक temporary/virtual table है।
-
Data original table से copy नहीं होता, सिर्फ query save होती है।
-
जब भी आप view को query करेंगे, latest data fetch होता है।
-
-
View का नाम यहाँ: Successful_Bookings
-
SELECT * FROM newbooking
-
newbookingtable से सभी columns select होंगे। -
*का मतलब: table का पूरा data।
-
-
WHERE
Booking Status= 'Success'-
Filter condition: केवल वो rows select होंगी जिनकी Booking Status success है।
-
Note: Column name में space होने की वजह से backticks
` `का use किया गया है।
-
Explanation:
-
अब आप view को table की तरह query कर सकते हैं।
-
इससे केवल successful bookings show होंगी।
-
Advantages of using View:
-
बार-बार लिखी जाने वाली complex query save हो जाती है।
-
Live data automatically update होता है अगर original table change होता है।
-
Simplifies reporting और analysis।
- Question: Get the total number of cancelled rides by customers
- Ans:
WHERE `Booking Status` = 'Canceled_by_Customer';
Step-by-Step Explanation:
1️⃣ SELECT COUNT(*)
-
COUNT(*)एक aggregate function है। -
इसका काम: rows की total संख्या गिनना।
-
*मतलब: हर row को count करो, चाहे उसमें NULL values हों या नहीं।
2️⃣ FROM newbooking
-
newbookingtable से data fetch किया जा रहा है। -
मतलब, rows की गिनती इस table के context में होगी।
3️⃣ WHERE Booking Status = 'Canceled_by_Customer'
-
WHEREclause filter apply करता है। -
केवल वो rows count होंगी जिनकी
Booking Statuscolumn value Canceled_by_Customer है। -
ध्यान: column name में space है इसलिए backticks
`Booking Status`use किए गए हैं।
4️⃣ पूरा मतलब
-
यह query आपको बताती है कि newbooking table में कितनी bookings customers द्वारा cancel की गई हैं।
Ans:
SELECT `Customer Id`, COUNT(`BOOKING ID`) as total_rides
Step-by-Step Notes
1️⃣ SELECT Customer Id, COUNT(Booking ID) AS total_rides
-
Customer Id→ यह column बताता है कि ride किस customer ने book की। -
COUNT(Booking ID)→ यह aggregate function है जो हर customer की total rides count करता है। -
AS total_rides→ यह counted column का नया नाम है।
मतलब: यहाँ हम हर customer के rides की संख्या निकाल रहे हैं।
2️⃣ FROM newbooking
-
Data source:
newbookingtable -
यानि हम वही table use कर रहे हैं जिसमें सारे ride details हैं।
3️⃣ GROUP BY Customer Id
-
GROUP BY→ rows को customer के हिसाब से group करता है। -
मतलब: एक ही customer की सारी bookings एक group में आएँगी।
-
हर customer के लिए एक row generate होगी।
4️⃣ ORDER BY total_rides DESC
-
ORDER BY→ data को sort करता है। -
DESC→ descending order, यानी सबसे ज्यादा rides वाले customer पहले आएँ।
5️⃣ LIMIT 5
-
LIMIT→ सिर्फ top 5 rows दिखाए। - मतलब यह query आपको बताएगी कि कौन-कौन से 5 customers ने सबसे ज्यादा rides की।
- Question:Find the maximum and minimum driver rating for prime sedan booking;
Ans:
Comments
Post a Comment