CLASS ORB!

"Direct & Bold" approach
Headline: Level Up Your Learning — For Free. Body: Master every subject from Class 6th to 12th with expert-led resources. No subscriptions, no barriers. Just pure knowledge.

Informatics Practices ! Notes Class 12 PDF Downlod

Informatics Practices! Notes Class 12

 

ip Informatics Practices
Informatics Practices

CLASS ORB.COM  Teacher: OM SIKARWAR

Chapter 1

Informatics Practices: Querying and SQL Functions

Class 12 | Informatics Practices

 

 CBSE | State Boards | Practical Exam Ready

 हमारी कक्षा के चार दोस्त

This chapter are describe four friends and a teacher to make it easy in story form  understanding for students

 अर्जुन

Topper — हर चीज़ seriously लेता है। SQL expert बनना चाहता है।

 प्रिया

Creative thinker — अच्छे examples से समझती है।

 रोहन

Funny guy — मज़ाकिया है पर समझदार भी।

 सोनू

Always confused — पर उसके सवाल सबसे अच्छे होते हैं।

 

 1.1 Introduction —Informatics Practices!

 

 Om Sir (Teacher)

बच्चों, Class XI में हमने databases बनाना और SQL queries से data retrieve करना सीखा था। आज हम उससे आगे जाएंगे — SQL के और powerful commands सीखेंगे जो real-life database problems solve करते हैं!

 

 रोहन

Sir, मतलब अब हम databases के असली ‘Hero’ बनेंगे? जैसे SQL Superhero! 

 

 Om Sir

बिल्कुल रोहन! इस chapter में हम सीखेंगे — Functions in SQL, GROUP BY, Operations on Relations, और दो tables को मिलाकर query कैसे लिखें। इसके लिए हम एक database बनाएंगे — CARSHOWROOM!

 

 CARSHOWROOM Database — 4 Tables

1. INVENTORY  — Car की details (CarID, CarName, Price, Model, Year, FuelType)

2. CUSTOMER   — Customer की info (CustID, CustName, CustAdd, Phone, Email)

3. SALE        — Sale की details (InvoiceNo, CarID, CustID, SaleDate, PaymentMode, EmpID, SalePrice)

4. EMPLOYEE    — Employee की info (EmpID, EmpName, DOB, DOJ, Designation, Salary)

 

 INVENTORY Table का Data (Table 1.1)

CarId

CarName

Price

Model

YearManufacture

FuelType

B001

Car1

582613.00

LXI

2017

Petrol

B002

Car1

673112.00

VXI

2018

Petrol

B003

Car2

447808.00

Si pact 2

2019

Petrol

B003

Car2

614768.00

Bolivi 2

2016

Petrol

 

 1.2 Functions in SQL

 

 Om Sir

बच्चों! Function का मतलब होता है एक ऐसा tool जो input लेता है और output देता है। SQL में भी functions होते हैं जो हमारे data पर calculations करते हैं।

 प्रिया

Sir, जैसे Calculator में + – × ÷ buttons होते हैं — वैसे ही SQL में functions होते हैं?

 

 Om Sir

Exactly प्रिया! बहुत अच्छा example दिया! SQL Functions दो types के होते हैं — Single Row Functions और Aggregate Functions।

 

 SQL Functions — दो Category

1️⃣  Single Row Functions (Scalar Functions):

    → एक row पर काम करते हैं और एक result देते हैं

    → 3 types: Numeric, String, Date & Time

2️⃣  Aggregate Functions (Multiple Row Functions):

    → पूरे table / group की rows पर काम करते हैं

    → एक single value return करते हैं

    → Examples: MAX(), MIN(), AVG(), SUM(), COUNT()

 

 1.2.1 Single Row Functions — Numeric Functions

 

 सोनू

Sir, Numeric Functions मतलब? Math वाले functions?

 

 Om Sir

हाँ सोनू! Numeric Functions numbers पर काम करते हैं। तीन main functions हैं — POWER(), ROUND(), और MOD()।

 

Function

काम क्या करता है?

Example

Output

POWER(x,y)

x की power y निकालता है

SELECT POWER(2,3)

8

ROUND(N,D)

N को D decimal places तक round करता है

SELECT ROUND(3.567, 2)

3.57

MOD(A,B)

A ÷ B का remainder देता है

SELECT MOD(11, 2)

1

 

 अर्जुन

Sir, ROUND() में D=0 हो तो? जैसे ROUND(4.6, 0)?

 

 Om Sir

शाबाश अर्जुन! D=0 हो तो nearest integer round होगा। ROUND(4.6, 0) = 5 और ROUND(4.3, 0) = 4।

 

 Example 1.1 — INVENTORY Table पर ROUND और MOD

 Car dealer EMIs निकालना चाहता है। Price का 12% GST calculate करें, FinalPrice add करें, 10 installments में बाँटें, और remainder निकालें:

 

— Step 1: GST calculate करें (Price का 12%)

mysql> SELECT ROUND(12/100*Price,1) ‘GST’ FROM INVENTORY;

— Step 2: FinalPrice column add करें

mysql> ALTER TABLE INVENTORY ADD FinalPrice Numeric(10,1);

mysql> UPDATE INVENTORY SET FinalPrice = ROUND(Price*12/100 + Price, 1);

— Step 3: EMI और Remaining Amount निकालें

mysql> SELECT CarId, FinalPrice, ROUND(FinalPrice/10, 0) ‘EMI’,

       MOD(FinalPrice, 10000) ‘Remaining Amount’ FROM INVENTORY;

 

 रोहन

Oh nice! तो EMI = FinalPrice ÷ 10 और जो बचा वो MOD से मिलेगा! एकदम simple!

 

 (B) String Functions — String पर काम करने वाले Functions

 

 Om Sir

String Functions text data पर operations करते हैं — जैसे uppercase करना, length निकालना, substring निकालना इत्यादि।

 

Function

काम

Example

Output

UCASE(str)

Uppercase करता है

SELECT UCASE(‘hello’)

HELLO

LCASE(str)

Lowercase करता है

SELECT LCASE(‘HELLO’)

hello

MID(str,pos,n)

बीच से n characters

SELECT MID(‘Informatics’,4,3)

orm

LENGTH(str)

Characters count

SELECT LENGTH(‘Hello’)

5

LEFT(str,n)

Left से n chars

SELECT LEFT(‘Computer’,4)

Comp

RIGHT(str,n)

Right से n chars

SELECT RIGHT(‘SCIENCE’,3)

NCE

INSTR(str,sub)

Position of substring

SELECT INSTR(‘Informatics’,’ma’)

9

LTRIM(str)

Left spaces remove

SELECT LTRIM(‘  Hello’)

Hello

RTRIM(str)

Right spaces remove

SELECT RTRIM(‘Hello  ‘)

Hello

TRIM(str)

Both side spaces remove

SELECT TRIM(‘  Hi  ‘)

Hi

 

 प्रिया

Sir, MID और SUBSTR same हैं क्या?

 

 Om Sir

हाँ प्रिया! MID() और SUBSTR() दोनों same काम करते हैं — MySQL में दोनों valid हैं। Syntax: MID(string, pos, n) → pos से n characters निकालो।

 

 Example 1.3 — CUSTOMER Table पर String Functions

— Customer name lowercase में, Email uppercase में

mysql> SELECT LOWER(CustName), UPPER(Email) FROM CUSTOMER;

— Email की length और ‘@’ से पहले का part

mysql> SELECT LENGTH(Email), LEFT(Email, INSTR(Email,’@’)-1) FROM CUSTOMER;

— Email से ‘.com’ हटाएं

mysql> SELECT REPLACE(Email,‘.com’,) FROM CUSTOMER;

 BOARD EXAM TIP

MID(), LEFT(), RIGHT(), INSTR() — इन सभी पर practical questions आते हैं। Syntax याद करें और एक-एक example खुद try करें!

 

 (C) Date and Time Functions

 

 सोनू

Sir, Date functions की ज़रूरत क्यों? Date तो date होती है!

 

 Om Sir

अरे सोनू! Database में dates store होती हैं — जैसे Date of Birth, Date of Joining। हमें उनसे Day, Month, Year अलग-अलग निकालने होते हैं, current date चाहिए होती है। इसलिए Date Functions!

 

Function

काम

Example

Output

NOW()

Current date & time

SELECT NOW()

2025-07-11 10:41:17

DATE()

Date part निकालें

SELECT DATE(NOW())

2025-07-11

MONTH(date)

Month number

SELECT MONTH(‘2025-07-11’)

7

MONTHNAME(date)

Month name

SELECT MONTHNAME(‘2025-11-28’)

November

YEAR(date)

Year निकालें

SELECT YEAR(‘2021-10-03’)

2021

DAY(date)

Day number

SELECT DAY(‘2013-03-24’)

24

DAYNAME(date)

Day का नाम

SELECT DAYNAME(‘2019-07-11’)

Thursday

 

 Example 1.4 — EMPLOYEE Table पर Date Functions

— सभी employees का joining day, month, year निकालें

mysql> SELECT DAY(DOJ), MONTH(DOJ), YEAR(DOJ) FROM EMPLOYEE;

— अगर DOJ Sunday नहीं है तो full date display करें

mysql> SELECT DAYNAME(DOJ), DAY(DOJ), MONTHNAME(DOJ), YEAR(DOJ)

       FROM EMPLOYEE WHERE DAYNAME(DOJ) != ‘Sunday’;

 

 1.2.2 Aggregate Functions (Multiple Row Functions)

 

 Om Sir

अब बात करते हैं Aggregate Functions की! ये functions पूरे table की सभी rows पर एक साथ काम करते हैं और एक single answer देते हैं।

 

 रोहन

जैसे Class का Average marks निकालना? पूरी class का एक number?

 

 Om Sir

Perfect example रोहन! बिल्कुल वैसे ही!

 

 Single Row vs Aggregate Functions — Difference

Single Row Functions:           Aggregate Functions:

✓ एक row पर काम                ✓ पूरी table / group पर काम

✓ हर row के लिए एक result      ✓ सब rows मिलाकर एक result

✓ WHERE में use हो सकते हैं    ✓ WHERE में use नहीं, HAVING में करते हैं

✓ Math, String, Date types      ✓ MAX, MIN, AVG, SUM, COUNT

Note: Column must be Numeric type (except COUNT)

 

Function

काम

Example

Output

MAX(col)

सबसे बड़ी value

SELECT MAX(Price) FROM INVENTORY

675112.00

MIN(col)

सबसे छोटी value

SELECT MIN(Price) FROM INVENTORY

447808.00

AVG(col)

Average value

SELECT AVG(Price) FROM INVENTORY

584965.80

SUM(col)

सब values का total

SELECT SUM(Price) FROM INVENTORY

4680733.00

COUNT(col)

NULL छोड़कर count

SELECT COUNT(EmpName) FROM EMPLOYEE

7

COUNT(*)

सभी rows count

SELECT COUNT(*) FROM MANAGER

4

 Example 1.5 — Aggregate Functions Practice

— VXI model की कितनी cars हैं?

mysql> SELECT COUNT(*) FROM INVENTORY WHERE Model = ‘VXI’;

Output: 2

— कितने different Models available हैं?

mysql> SELECT COUNT(DISTINCT Model) FROM INVENTORY;

Output: 6

— LXI model की average price?

mysql> SELECT AVG(Price) FROM INVENTORY WHERE Model = ‘LXI’;

Output: 548300.500000

 

 EXAM IMPORTANT

COUNT(*) सभी rows count करता है — NULL भी। COUNT(column) NULL rows skip करता है। यह difference exam में पूछा जाता है!

 

 1.3 GROUP BY in SQL

 

 Om Sir

बच्चों! कभी-कभी हमें rows को groups में बाँटकर calculate करना होता है। जैसे — ‘हर customer ने कितनी cars खरीदीं?’ इसके लिए GROUP BY use करते हैं।

 

 प्रिया

Sir, जैसे school में section-wise attendance निकालते हैं — Section A में 40, B में 35? वैसे groups?

 

 Om Sir

Exactly! GROUP BY same columns की rows को एक group में रखता है, फिर उस group पर aggregate function apply होता है।

 

 GROUP BY — Syntax

SELECT column, AGGREGATE_FUNCTION(column)

FROM table_name

[WHERE condition]

GROUP BY column

[HAVING condition]

[ORDER BY column];

  Important: SELECT में वही columns आ सकते हैं जो:

   → GROUP BY में हों, OR

   → Aggregate Function में wrapped हों

 

▶ Example 1.6 — SALE Table पर GROUP BY

— (a) हर Customer ने कितनी Cars खरीदीं?

mysql> SELECT CustID, COUNT(*) ‘Number of Cars’

       FROM SALE GROUP BY CustID;

— (b) 1 से ज़्यादा car खरीदने वाले Customers?

mysql> SELECT CustID, COUNT(*) FROM SALE

       GROUP BY CustID HAVING Count(*) > 1;

— (c) हर Payment Mode में कितने लोग?

mysql> SELECT PaymentMode, Count(PaymentMode) FROM SALE

       GROUP BY PaymentMode ORDER BY PaymentMode;

— (d) कौन से Payment Mode 1 से ज़्यादा बार use हुए?

mysql> SELECT PaymentMode, Count(PaymentMode) FROM SALE

       GROUP BY PaymentMode HAVING COUNT(*) > 1;

 

 सोनू

Sir, WHERE और HAVING में क्या difference है? दोनों conditions के लिए तो हैं?

 

 Om Sir

बहुत important सवाल, सोनू! WHERE → individual rows को filter करता है (GROUP BY से पहले)। HAVING → groups को filter करता है (GROUP BY के बाद)। Aggregate functions HAVING में use होते हैं, WHERE में नहीं!

 

WHERE

HAVING

Individual rows filter करता है

Groups को filter करता है

GROUP BY से पहले apply होता है

GROUP BY के बाद apply होता है

Aggregate functions use नहीं हो सकते

Aggregate functions use हो सकते हैं

WHERE Price > 500000

HAVING COUNT(*) > 1

 

 1.4 Operations on Relations

 

 Om Sir

बच्चों! कभी-कभी हमें दो अलग tables की rows को combine करना होता है। इसके लिए Set Operations होती हैं — UNION, INTERSECT, और MINUS।

 

 अर्जुन

Sir, जैसे Maths में Sets में Union, Intersection होता है — A ∪ B, A ∩ B — वैसे ही?

 

 Om Sir

Brilliant! Exactly वैसे ही! बस conditions हैं: दोनों tables में same number of columns हों, और corresponding columns का same domain हो।

 

📋 DANCE और MUSIC Tables — Example Setup

DANCE Table:              MUSIC Table:

SNo  Name     Class       SNo  Name      Class

 1   Aastha   7A           1   Mehak     8A

 2   Mahira   6A           2   Mahira    6A

 3   Mohit    7B           3   Lavanya   7A

 4   Sanjay   7A           4   Sanjay    7A

                           5   Abhay     8A

 

 1.4.1 UNION (U)

 Om Sir

UNION → दोनों tables की सभी rows combined, duplicate एक बार ही आएंगे।

 

— DANCE या MUSIC में participate करने वाले सभी students

mysql> SELECT * FROM DANCE UNION SELECT * FROM MUSIC;

Result: Mahira और Sanjay दोनों में हैं, पर एक बार ही आएंगे।

Total rows: 7 (unique students)

 

 1.4.2 INTERSECT (∩)

 Om Sir

INTERSECT → सिर्फ वो rows जो दोनों tables में common हैं।

 

— दोनों में participate करने वाले students

mysql> SELECT SELECT * FROM DANCE
WHERE Name IN
(SELECT Name FROM MUSIC);

Result:

SNo  Name    Class

 2   Mahira  6A

 4   Sanjay  7A

 

 1.4.3 MINUS (−)

 Om Sir

MINUS → पहली table में हैं पर दूसरी में नहीं — सिर्फ वो rows।

 

— DANCE में हैं पर MUSIC में नहीं

mysql> SELECT ** FROM DANCE
WHERE Name NOT IN
(SELECT Name FROM MUSIC);;

Result:

SNo  Name    Class

 1   Aastha  7A

 3   Mohit   7B

 5   Lavanya 7A

 6   Abhay   8A

 

 1.4.4 Cartesian Product (×)

 सोनू

Sir, Cartesian Product? यह तो Maths में था!

 

 Om Sir

हाँ सोनू! Cartesian Product में दोनों tables की हर row एक-दूसरे से combine होती है। अगर DANCE में 4 rows और MUSIC में 5 rows हैं, तो result में 4×5 = 20 rows होंगी!

 

 Cartesian Product Rules

• Degree (columns) = degree of table1 + degree of table2

• Cardinality (rows) = rows1 × rows2

• DANCE (4 rows, 3 cols) × MUSIC (5 rows, 3 cols) = 20 rows, 6 cols

• SQL Command: SELECT * FROM DANCE, MUSIC;

 1.5 Using Two Relations in a Query

 

 Om Sir

अब तक हमने single table पर queries लिखी थीं। पर real life में data multiple tables में होता है। जैसे — Car का नाम INVENTORY में है, पर उसे किसने खरीदा यह SALE में है। दोनों से information चाहिए — तो JOIN!

 

 प्रिया

Sir, JOIN मतलब दो tables को एक बनाना? जैसे puzzle pieces जोड़ना?

 

 Om Sir

Perfect analogy प्रिया! JOIN दो tables को एक condition के आधार पर combine करता है।

 

 1.5.1 Cartesian Product on Two Tables

— Example 1.7: DANCE और MUSIC के सभी combinations

— (a) सभी combinations

mysql> SELECT * FROM DANCE, MUSIC;

Result: 4 × 5 = 20 rows (degree = 6)

— (b) Same Name वाले combinations (Condition लगाई)

mysql> SELECT * FROM DANCE D, MUSIC M WHERE D.Name = M.Name;

Result: Mahira (6A) और Sanjay (7A) — 2 rows

 

 1.5.2 JOIN on Two Tables

 

 Om Sir

JOIN करने के 3 तरीके हैं। CARSHOWROOM के UNIFORM और COST tables लेते हैं:

 

UNIFORM और COST Tables

UNIFORM: UCode, UName, UColor        COST: UCode, Size, Price

   1      Shirt    White              1     L    500

   2      Pant     Grey               1     M    300

   3      Tie      Blue               2     L    400

                                      2     M    815

 

▶ Method (a) — WHERE Clause

mysql> SELECT * FROM UNIFORM, COST WHERE UNIFORM.UCode = COST.UCode;

Result: 4 rows — UCode both tables में match होने पर

 

▶ Method (b) — Explicit JOIN Clause

mysql> SELECT * FROM UNIFORM U JOIN COST C ON U.UCode = C.UCode;

— Table aliases U और M use किए ambiguity avoid करने के लिए

 

▶ Method (c) — NATURAL JOIN

mysql> SELECT * FROM UNIFORM NATURAL JOIN COST;

Result: Same as above पर UCode column एक बार ही आता है!

— NATURAL JOIN common column को automatically match करता है

 

 JOIN के Important Points

• N tables join करने के लिए minimum N-1 JOINs चाहिए

• Table aliases (U, C, D, M) ambiguity से बचाते हैं

• NATURAL JOIN redundant column नहीं दिखाता

• JOIN clause में ON condition — WHERE की ज़रूरत नहीं

• Any relational operator (=, >, <) JOIN condition में use हो सकता है

 

 Summary — Quick Revision

 

Topic

Key Points

SQL Functions

Single Row (Numeric, String, Date) + Aggregate Functions

POWER(x,y)

x की y power — POWER(2,3) = 8

ROUND(N,D)

D decimal तक round — ROUND(3.567,2) = 3.57

MOD(A,B)

Remainder — MOD(11,2) = 1

UCASE/LCASE

Uppercase/Lowercase string

MID(str,pos,n)

Substring — MID(‘Informatics’,4,3) = ‘orm’

LENGTH(str)

String की length

NOW()/DATE()

Current datetime / date

MONTH/YEAR/DAY

Date से parts निकालें

Aggregate Functions

MAX, MIN, AVG, SUM, COUNT — group पर काम

GROUP BY

Same value वाली rows को group में रखें

HAVING

Groups पर condition — Aggregate functions use होते हैं

UNION

दोनों tables मिलाकर, duplicates एक बार

INTERSECT

Common rows only

MINUS

पहले में हैं, दूसरे में नहीं

Cartesian Product

सभी rows × rows combinations

JOIN / NATURAL JOIN

Condition पर tables combine

 

 Important Exam Questions

 1 Mark Questions

  1. SQL में Single Row और Aggregate Functions में क्या अंतर है?
  2. ROUND(5.678, 1) का output क्या होगा?
  3. MOD(17, 5) का output बताइए।
  4. WHERE और HAVING clause में क्या difference है?
  5. NATURAL JOIN का क्या काम है?
  6. COUNT(*) और COUNT(column) में फर्क बताइए।

 

 2-3 Marks Questions

  1. INVENTORY table से सभी cars का FuelType और उनकी average Price निकालें।
  2. SALE table से वो PaymentMode बताएं जो 2 से ज़्यादा बार use हुई।
  3. CUSTOMER table से सभी customers के email से domain name हटाकर दिखाएं।
  4. EMPLOYEE table से वो employees बताएं जो Saturday को join हुए।

 

 5 Marks Questions

  1. CARSHOWROOM database बनाएं और INVENTORY, CUSTOMER, SALE, EMPLOYEE tables create करें। Primary keys और Foreign keys identify करें।
  2. UNIFORM और COST tables को तीनों methods से JOIN करें और output compare करें।
  3. DANCE और MUSIC tables पर UNION, INTERSECT, और MINUS operations perform करें।

 

  CLASS ORB.COM  |  Teacher: OM SIKARWAR  |  Informatics Practices Class 12  

Informatics Practices! Notes Class 12 PDF Download Hindi

Informatics Practices! Notes Class 12 PDF Download English

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top