SlideShare una empresa de Scribd logo
1 de 8
//Downloaded From www.c4cpp.co.nr
//(C)2009.All rights reserved.
STRUCTURED QUERY LANGUAGE-
1
TABLE: SPORTS
Student
No:
class Name Game 1 Grade 1 Game 2 Grade 2
10 7 Sammer Cricket B Swimming A
11 8 Sujith Tennis A Skating C
12 7 Kamal Swimming B Football B
13 7 Venna Tennis C Tennis A
14 9 Archana Basketball A Cricket A
15 10 Arpit Cricket A Athletics C
WRITE THE SQL COMMANDS FOR (1) TO (7) ON THE BASIS
OF THE TABLE SPORTS
1) Display the names of students who have grade ‘C ’in either Game 1
or Game 2 or both.
SELECT NAME
FROM SPORTS
WHERE GRADE 1 =’C’. OR. GRADE 2 = ‘C’;
OUTPUT
NAME
SUJITH
VENNA
ARPIT
2)Display the number of students getting grade ‘A’ in cricket.
SELECT COUNT (*) FROM SPORTS
WHERE GRADE1 =”A” .AND. GAME2=”CRICKET” .OR. GRADE2 =”A”
.AND. GAME2=”CRICKET”;
OUTPUT
COUNT(*)
2
3)Display the names of the students who have same game for both Game 1
and Game 2.
SELECT NAME FROM SPORTS
WHERE GAME 1 =GAME 2;
OUTPUT
NAME
VENNA
4)Display the games taken up by the students ,whose name starts with ‘A’.
SELECT GAME1,GAME2
FROM SPORTS
WHERE NAME LIKE (”A%”);
OUTPUT
GAME1 GAME2
BASKETBALL CRICKET
CRICKET ATHELETICS
5) Add a new column named ‘Marks’.
ALTER TABLE SPORTS
ADD MARKS FLOAT (6, 2);
OUTPUT
ONE COLUMN ADDED
6)Assign a value 200 for Marks for all those who are getting grade ‘B’ or grade
‘A’ in both Game1 and Game2.
UPDATE SPORTS SET MARKS =200
WHERE GRADE1<=”B” AND. GRADE2<=”B”;
OUTPUT
3 RECORDS UPDATED
7)Arrange the whole table in the alphabetical order by name.
SELECT*FROM SPORTS
ORDER BY NAME;
OUTPUT
Student
No:
class Name Game 1 Grade 1 Game 2 Grade 2
14 9 Archana Basketball A Cricket A
15 10 Arpith Cricket A Athletics C
12 7 Kamal Swimming B Football B
10 7 Sammer Cricket B Swimming A
11 8 Sujith Tennis A Skating C
13 7 Venna Tennis C Tennis A
STRUCTURED QUERY LANGUAGE
-2
TABLE:STUDENT
No: Name Stipend Stream Avgmark Grade Class
1 Karan 400.00 Medical 78.5 B 12B
2 Divakar 450.00 Commerce 89.2 A 11C
3 Divya 300.00 Commerce 68.6 C 12C
4 Arun 350.00 Humanities 73.1 B 12C
5 Sabina 500.00 Nonmedical 90.6 A 11A
6 John 400.00 Medical 75.4 B 12B
7 Robert 250.00 Humanities 64.4 C 11A
8 Rubina 450.00 Nonmedical 88.5 A 12A
9 Vikas 500.00 Nonmedical 92.0 A 12A
10 Mohan 300.00 Commerce 67.5 C 12C
WRITE SQL COMMANDS FOR QUESTIONS 1 TO 7 ON THE BASIS OF
TABLE STUDENT
1)Select all the Nonmedical stream students from STUDENT.
SELECT NAME
FROM STUDENT
WHERE STREAM=’NONMEDICAL’;
OUTPUT
NAME:
SABINA
RUBINA
VIKAS
2)list the names of those students who are in class 12 sorted by stipend
SELECT NAME,STIPEND FROM STUDENT
WHERE CLASS=’12’
ORDER BY STIPEND;
OUTPUT
NAME STIPEND
DIVYA 300.00
MOHAN 300.00
ARUN 350.00
KARAN 400.00
JOHN 400.00
RUBINA 450.00
VIKAS 500.00
3)list all students sorted by avgmark in descending order
SELECT NAME FROM STUDENT
ORDER BY AVGMARK DESC;
OUTPUT
ROBERT
MOHAN
DIVYA
ARUN
JOHN
KARAN
RUBINA
DIVAKAR
SABINA
VIKAS
4)To count the number of students with grade “A”
SELECT COUNT(GRADE)
FROM STUDENT
WHERE GRADE=”A”;
OUTPUT
4
5)to insert a new student in the table anf fill the columns with some values
INSERT INTO STUDENT VALUES
(11,”MANISHA”,300.00,”NONMEDICAL”,72.5,”B”,12C);
OUTPUT
ONE ROW ADDED
6)give the output of the following SQL statement:
A)SELECT MIN(AVGMARK)
FROM STUDENT
WHERE AVGMARK<75;
OUTPUT
64.4
B)SELECT SUM(STIPEND) FROM STUDENT WHERE GRADE=”B”
OUTPUT
1150.00
C)SELECT AVG(STIPEND)FROM STUDENT WHERE CLASS=”12A”;
OUTPUT
475.00
D)SELECT COUNT(DISTINCT)
OUTPUT
10

Más contenido relacionado

Destacado

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Destacado (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Structured query language

  • 1. //Downloaded From www.c4cpp.co.nr //(C)2009.All rights reserved. STRUCTURED QUERY LANGUAGE- 1 TABLE: SPORTS Student No: class Name Game 1 Grade 1 Game 2 Grade 2 10 7 Sammer Cricket B Swimming A 11 8 Sujith Tennis A Skating C 12 7 Kamal Swimming B Football B 13 7 Venna Tennis C Tennis A 14 9 Archana Basketball A Cricket A 15 10 Arpit Cricket A Athletics C
  • 2. WRITE THE SQL COMMANDS FOR (1) TO (7) ON THE BASIS OF THE TABLE SPORTS 1) Display the names of students who have grade ‘C ’in either Game 1 or Game 2 or both. SELECT NAME FROM SPORTS WHERE GRADE 1 =’C’. OR. GRADE 2 = ‘C’; OUTPUT NAME SUJITH VENNA ARPIT 2)Display the number of students getting grade ‘A’ in cricket. SELECT COUNT (*) FROM SPORTS WHERE GRADE1 =”A” .AND. GAME2=”CRICKET” .OR. GRADE2 =”A” .AND. GAME2=”CRICKET”; OUTPUT COUNT(*) 2 3)Display the names of the students who have same game for both Game 1 and Game 2. SELECT NAME FROM SPORTS WHERE GAME 1 =GAME 2; OUTPUT NAME
  • 3. VENNA 4)Display the games taken up by the students ,whose name starts with ‘A’. SELECT GAME1,GAME2 FROM SPORTS WHERE NAME LIKE (”A%”); OUTPUT GAME1 GAME2 BASKETBALL CRICKET CRICKET ATHELETICS 5) Add a new column named ‘Marks’. ALTER TABLE SPORTS ADD MARKS FLOAT (6, 2); OUTPUT ONE COLUMN ADDED 6)Assign a value 200 for Marks for all those who are getting grade ‘B’ or grade ‘A’ in both Game1 and Game2. UPDATE SPORTS SET MARKS =200 WHERE GRADE1<=”B” AND. GRADE2<=”B”; OUTPUT 3 RECORDS UPDATED 7)Arrange the whole table in the alphabetical order by name. SELECT*FROM SPORTS ORDER BY NAME;
  • 4. OUTPUT Student No: class Name Game 1 Grade 1 Game 2 Grade 2 14 9 Archana Basketball A Cricket A 15 10 Arpith Cricket A Athletics C 12 7 Kamal Swimming B Football B 10 7 Sammer Cricket B Swimming A 11 8 Sujith Tennis A Skating C 13 7 Venna Tennis C Tennis A
  • 5. STRUCTURED QUERY LANGUAGE -2 TABLE:STUDENT No: Name Stipend Stream Avgmark Grade Class 1 Karan 400.00 Medical 78.5 B 12B 2 Divakar 450.00 Commerce 89.2 A 11C 3 Divya 300.00 Commerce 68.6 C 12C 4 Arun 350.00 Humanities 73.1 B 12C 5 Sabina 500.00 Nonmedical 90.6 A 11A 6 John 400.00 Medical 75.4 B 12B 7 Robert 250.00 Humanities 64.4 C 11A 8 Rubina 450.00 Nonmedical 88.5 A 12A 9 Vikas 500.00 Nonmedical 92.0 A 12A 10 Mohan 300.00 Commerce 67.5 C 12C
  • 6. WRITE SQL COMMANDS FOR QUESTIONS 1 TO 7 ON THE BASIS OF TABLE STUDENT 1)Select all the Nonmedical stream students from STUDENT. SELECT NAME FROM STUDENT WHERE STREAM=’NONMEDICAL’; OUTPUT NAME: SABINA RUBINA VIKAS 2)list the names of those students who are in class 12 sorted by stipend SELECT NAME,STIPEND FROM STUDENT WHERE CLASS=’12’ ORDER BY STIPEND; OUTPUT NAME STIPEND DIVYA 300.00 MOHAN 300.00 ARUN 350.00 KARAN 400.00 JOHN 400.00 RUBINA 450.00 VIKAS 500.00 3)list all students sorted by avgmark in descending order SELECT NAME FROM STUDENT ORDER BY AVGMARK DESC;
  • 7. OUTPUT ROBERT MOHAN DIVYA ARUN JOHN KARAN RUBINA DIVAKAR SABINA VIKAS 4)To count the number of students with grade “A” SELECT COUNT(GRADE) FROM STUDENT WHERE GRADE=”A”; OUTPUT 4 5)to insert a new student in the table anf fill the columns with some values INSERT INTO STUDENT VALUES (11,”MANISHA”,300.00,”NONMEDICAL”,72.5,”B”,12C); OUTPUT ONE ROW ADDED 6)give the output of the following SQL statement: A)SELECT MIN(AVGMARK) FROM STUDENT WHERE AVGMARK<75; OUTPUT 64.4 B)SELECT SUM(STIPEND) FROM STUDENT WHERE GRADE=”B” OUTPUT
  • 8. 1150.00 C)SELECT AVG(STIPEND)FROM STUDENT WHERE CLASS=”12A”; OUTPUT 475.00 D)SELECT COUNT(DISTINCT) OUTPUT 10