Functions & Aggregations in sql in hindi in hindi
Functions & Aggregations in SQL
SEO Optimized Table of Contents – Functions & Aggregations in SQL in Hindi
Functions & Aggregations in SQL in Hindi
आज के time में Database हर IT course और college exam का core part बन चुका है। SQL में data को सिर्फ store करना ही नहीं, बल्कि us data से meaningful information निकालना भी बहुत ज़रूरी होता है। यही काम SQL Functions और Aggregations करते हैं।
इस part में हम step-by-step, simple classroom language में समझेंगे कि Functions & Aggregations in SQL in hindi क्या होते हैं, और इन्हें exam point of view से कैसे याद रखना चाहिए।
Introduction to Functions & Aggregations in SQL
SQL Functions ऐसे predefined operations होते हैं जो table के data पर calculation करते हैं। Aggregation Functions पूरे column के data को देखकर एक single value return करते हैं।
College exams में ज़्यादातर सवाल Aggregation Functions से आते हैं क्योंकि ये real-world data analysis में बहुत use होते हैं। इसलिए concept clear होना बहुत ज़रूरी है।
Aggregation Functions हमेशा numeric ya countable data पर काम करते हैं और अक्सर GROUP BY clause के साथ use किए जाते हैं।
Why Functions & Aggregations are Important in SQL
- Large data से summary निकालने में help करते हैं
- Reports और results generate करने में use होते हैं
- Exam में direct theory + query questions आते हैं
- Real projects में performance improve करते हैं
COUNT Function in SQL
COUNT Function SQL का सबसे basic और most used aggregation function है। यह function table में total number of rows या values को count करता है।
COUNT Function exam में बहुत popular है क्योंकि यह easy है और direct questions पूछे जाते हैं। यह function NULL values को count नहीं करता।
Syntax of COUNT Function
SELECT COUNT(column_name) FROM table_name;
अगर आप सभी rows को count करना चाहते हैं, तो * का use किया जाता है।
SELECT COUNT(*) FROM table_name;
Example of COUNT Function
मान लीजिए हमारे पास students नाम की table है।
| id | name | marks |
|---|---|---|
| 1 | Amit | 80 |
| 2 | Neha | 75 |
| 3 | Ravi | NULL |
अगर हम marks column पर COUNT apply करें:
SELECT COUNT(marks) FROM students;
Result होगा 2 क्योंकि NULL value count नहीं होती।
SUM Function in SQL
SUM Function numeric data का total निकालने के लिए use होता है। यह function पूरे column की values को जोड़ देता है।
SUM Function mainly salary, marks, price जैसे fields पर apply किया जाता है। यह भी NULL values को ignore करता है।
Syntax of SUM Function
SELECT SUM(column_name) FROM table_name;
Example of SUM Function
अगर हम students table में सभी students के marks का total निकालना चाहते हैं:
SELECT SUM(marks) FROM students;
इसका output होगा 155 क्योंकि NULL value add नहीं होगी।
Exam में SUM से जुड़े सवाल direct query ya output predict करने वाले होते हैं। इसलिए syntax और behavior अच्छे से याद रखना चाहिए।
AVG Function in SQL
AVG Function किसी numeric column का average निकालता है। यह SUM और COUNT दोनों internally use करता है।
AVG Function में total sum को total non-NULL rows से divide किया जाता है। इसलिए NULL values average calculation में include नहीं होती।
Syntax of AVG Function
SELECT AVG(column_name) FROM table_name;
Example of AVG Function
Students table में marks का average निकालने के लिए:
SELECT AVG(marks) FROM students;
Calculation होगी (80 + 75) / 2 = 77.5
College exams में अक्सर पूछा जाता है कि AVG Function NULL values को कैसे handle करता है। Answer यही है कि NULL values ignore होती हैं।
Key Points for Exam Preparation
- COUNT(*) सभी rows count करता है
- COUNT(column) NULL ignore करता है
- SUM और AVG केवल numeric data पर काम करते हैं
- Aggregation Functions single value return करते हैं
इस first part में आपने COUNT, SUM और AVG Functions को detail में समझा। Next part में हम MIN, MAX, GROUP BY और HAVING Clause को deeply cover करेंगे जो exams और practical दोनों के लिए बहुत important हैं।
MIN Function in SQL
MIN Function का use किसी column की सबसे छोटी value निकालने के लिए किया जाता है। यह function numeric, date और text data तीनों पर काम कर सकता है।
College exams में MIN Function से जुड़े सवाल अक्सर output based या short query वाले होते हैं, इसलिए इसका behavior अच्छे से समझना ज़रूरी है।
Syntax of MIN Function
SELECT MIN(column_name) FROM table_name;
Example of MIN Function
मान लीजिए हमारे पास students table है जिसमें marks दिए गए हैं।
SELECT MIN(marks) FROM students;
इस query का output होगा सबसे कम marks। अगर किसी row में NULL value है, तो MIN Function उसे ignore कर देता है।
Text data में MIN Function alphabetical order के हिसाब से smallest value return करता है, जो exam में एक common trick question होता है।
MAX Function in SQL
MAX Function MIN का opposite होता है। यह किसी column की सबसे बड़ी value return करता है।
यह function salary, marks, price जैसे fields के लिए बहुत useful होता है और reports बनाने में extensively use किया जाता है।
Syntax of MAX Function
SELECT MAX(column_name) FROM table_name;
Example of MAX Function
SELECT MAX(marks) FROM students;
इसका output होगा highest marks। यह भी NULL values को ignore करता है।
Exam point of view से ध्यान रखने वाली बात यह है कि MAX Function हमेशा single value return करता है, chahe table में कितनी भी rows क्यों न हों।
Difference between MIN and MAX Function
| MIN Function | MAX Function |
|---|---|
| Smallest value return करता है | Largest value return करता है |
| NULL values ignore करता है | NULL values ignore करता है |
| Ascending logic follow करता है | Descending logic follow करता है |
GROUP BY Clause in SQL
GROUP BY Clause SQL का सबसे important concept माना जाता है। यह clause rows को groups में divide करता है और हर group पर aggregation apply करता है।
Simple words में कहें तो GROUP BY data को category-wise analyze करने में मदद करता है। Exams में यह topic बहुत high weight रखता है।
Why GROUP BY is Required
- Category wise result निकालने के लिए
- Department wise salary calculate करने के लिए
- Subject wise average marks जानने के लिए
Syntax of GROUP BY Clause
SELECT column_name, AGG_FUNCTION(column_name)
FROM table_name
GROUP BY column_name;
Example of GROUP BY Clause
मान लीजिए students table में एक नया column है class।
SELECT class, AVG(marks)
FROM students
GROUP BY class;
यह query हर class का average marks अलग-अलग निकाल देगी। यही GROUP BY की real power है।
Exam में अक्सर पूछा जाता है कि GROUP BY के साथ SELECT में वही column आ सकता है जो GROUP BY में लिखा गया हो या aggregation function में use हुआ हो।
Rules of GROUP BY for Exams
- SELECT में non-aggregated column GROUP BY में होना चाहिए
- WHERE clause GROUP BY से पहले लिखा जाता है
- GROUP BY aggregation functions के साथ use होता है
HAVING Clause in SQL
HAVING Clause का use GROUP BY के result पर condition लगाने के लिए किया जाता है। यह WHERE clause जैसा ही होता है, लेकिन aggregation ke baad apply होता है।
यह concept exams में confusion create करता है, इसलिए HAVING और WHERE का difference clear होना ज़रूरी है।
Syntax of HAVING Clause
SELECT column_name, AGG_FUNCTION(column_name)
FROM table_name
GROUP BY column_name
HAVING condition;
Example of HAVING Clause
अगर हमें केवल वही classes दिखानी हैं जिनका average marks 70 से ज़्यादा है:
SELECT class, AVG(marks)
FROM students
GROUP BY class
HAVING AVG(marks) > 70;
यह query पहले data को class wise group करेगी और फिर condition apply करेगी।
Difference between WHERE and HAVING Clause
| WHERE Clause | HAVING Clause |
|---|---|
| Rows पर condition लगाता है | Groups पर condition लगाता है |
| Aggregation से पहले execute होता है | Aggregation के बाद execute होता है |
| Aggregation functions use नहीं कर सकता | Aggregation functions use कर सकता है |
Important Exam Notes for HAVING Clause
- HAVING हमेशा GROUP BY के साथ use होता है
- Aggregation function HAVING में allowed है
- WHERE और HAVING को mix करना allowed है
इस part में आपने MIN, MAX, GROUP BY और HAVING Clause को detail में समझा। अब Functions & Aggregations in SQL in hindi का पूरा concept exam और practical दोनों के लिए clear हो चुका है।
FAQs
SQL Functions & Aggregations in hindi ऐसे predefined operations होते हैं जो database table के data पर calculation करके meaningful result देते हैं। Aggregation Functions पूरे column के data को analyze करके single value return करते हैं, जैसे COUNT, SUM, AVG, MIN और MAX।
COUNT Function in hindi table में मौजूद rows या values की total संख्या निकालने के लिए use होता है। COUNT(*) सभी rows को count करता है, जबकि COUNT(column_name) NULL values को ignore करता है। यह exam में सबसे ज्यादा पूछे जाने वाले SQL Functions में से एक है।
SUM Function in hindi किसी numeric column की total value निकालता है, जबकि AVG Function in hindi उसी column का average calculate करता है। दोनों functions NULL values को ignore करते हैं और numeric data पर ही apply किए जाते हैं।
MIN Function in hindi किसी column की सबसे छोटी value return करता है, जबकि MAX Function in hindi सबसे बड़ी value निकालता है। ये functions numeric, date और text data तीनों पर काम कर सकते हैं और NULL values को ignore करते हैं।
GROUP BY Clause in hindi data को category wise groups में divide करता है और हर group पर aggregation apply करता है। Exam में department wise salary, class wise average marks जैसे सवाल GROUP BY से ही पूछे जाते हैं।
WHERE Clause rows पर condition लगाता है और aggregation से पहले execute होता है, जबकि HAVING Clause groups पर condition लगाता है और aggregation के बाद apply होता है। HAVING Clause in hindi aggregation functions के साथ use किया जा सकता है, जो WHERE में possible नहीं है।