0% found this document useful (0 votes)
55 views

Xii SQL Record Queries

The document describes SQL queries on a student table containing details like roll number, name, gender, date of birth, and marks. It includes queries to: 1) Display details of students with marks over 80; 2) Display names truncated and rounded marks for females; 3) Display transformed name, gender, and name length for students starting with R; 4) Group and filter students and display transformed names and marks between 70-90; 5) Display names ending in i with month and year of birth. It also orders, groups, filters, and aggregates results in various ways like finding maximum/minimum marks by gender, counts by year, and more.

Uploaded by

Shiva4 Pro
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Xii SQL Record Queries

The document describes SQL queries on a student table containing details like roll number, name, gender, date of birth, and marks. It includes queries to: 1) Display details of students with marks over 80; 2) Display names truncated and rounded marks for females; 3) Display transformed name, gender, and name length for students starting with R; 4) Group and filter students and display transformed names and marks between 70-90; 5) Display names ending in i with month and year of birth. It also orders, groups, filters, and aggregates results in various ways like finding maximum/minimum marks by gender, counts by year, and more.

Uploaded by

Shiva4 Pro
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

MYSQL QUERIES

STD XII (2022-2023)

a. Create a stu table with the below given details, add primary key and not
null constraints.
Table : stu

rollno name gender dob mark

1 Gokul M 2004-01-11 94.50

2 Meena F 2003-03-14 87.00

3 Mani M 2002-08-16 68.00

4 Raji F 2004-09-25 81.50

5 Banu F 2003-02-19 91.75

6 Sharma M 2002-11-20 78.75

create table stu(rollno int PRIMARY KEY, name varchar(25),gender


char(1),dob date, mark decimal(10,2) NOT NULL);

b. Insert values into the table stu


insert into stu values(1, "Gokul","M","2004-01-11",94.50);
insert into stu values(2, "Meena","F","2003-03-14",87.00);
insert into stu values(3,"Mani","M","2002-08-16",68.00);
insert into stu values(4,"Raji","F","2004-09-25",81.50);
insert into stu values(5,"Banu","F","2003-02-19",91.75);
insert into stu values(6,"Sharma","M","2002-11-20",78.75);

1. Display the details of the students with marks more than 80.
select * from stu where mark>80;

rollno name gender dob mark

1 Gokul M 2004-01-11 94.50

2 Meena F 2003-03-14 87.00


4 Raji F 2004-09-25 81.50

5 Banu F 2003-02-19 91.75

2. Display 2 characters of name from left and round the mark whose
gender is ‘f’
select left(name,2), round(mark) from stu where gender='F';

left(name,2) round(mark)

Me 87

Ra 82

Ba 92

3. Display upper of name, lower of gender and length of name whose name
starts with R
select upper(name),lower(gender),length(name) from stu where name like 'R
%';

upper(name) lower(gender) length(name)

RAJI f 4

4. Display name from 3rd place and 2 characters whose mark is in the
range 70-90.
select mid(name,3,2) from stu where mark between 70 and 90;

mid(name,3,2)

en

ji

ar
5. Display name, month, year of dob whose name ends with ‘i'
select name, month(dob),year(dob) from stu where name like '%i';

name month(dob) year(dob)

Mani 8 2002

Raji 9 2004

6. Display dob, gender whose name contains ‘a’ anywhere and gender is
not ‘M’
select dob, gender from stu where name like '%a%' and gender not like 'M';

dob gender

2003-03-14 F

2004-09-25 F

2003-02-19 F

7. Display name and mark whose dob begins with 2004


select name, mark from stu where dob like ‘2004%’;

name mark

Gokul 94.50

Raji 81.50

8. Display name, dob, mark of male students in ascending order of their


names.
select name, dob, mark from stu where gender="M" order by name;
name dob mark

Gokul 2004-01-11 94.50

Mani 2002-08-16 68.00

Sharma 2002-11-20 78.75

9. Display gender, dob, mark from stu in descending order of their mark
whose rollno is above 3
select gender, dob, mark from stu where rollno>3 order by mark desc;

gender dob mark

F 2003-02-19 91.75

F 2004-09-25 81.50

M 2002-11-20 78.75

10. Display total number of students year wise.


select count(*) from stu group by year(dob);

count(*)

11. Display maximum, minimum of mark obtained by each gender.


select max(mark), min(mark) from stu group by gender;

max(mark) min(mark)

94.50 68.00

91.75 81.50
12. Display gender, total mark gender wise whose mark is not below 200.
select gender, sum(mark) from stu group by gender having sum(mark) >
200;

gender sum(mark)

M 241.25

F 260.25

13. Display year of dob, avg of mark year wise whose average of mark is
not above 100.
select year(dob), avg(mark) from stu group by year(dob) having avg(mark)
< 100;

year(dob) avg(mark)

2004 88.000000

2003 89.375000

2002 73.375000

14. Display dayname of dob, total number of records gender wise whose
mark is above 75 and total records more than once

select dayname(dob), count(*) from stu where mark>75 group by gender


having count(*)>1;

dayname(dob) count(*)

Sunday 2
Friday 3

15. Display the position of ‘a’ in name and total mark in each gender whose
rollno is above 1 and total mark greater than 100

select instr(name,'a'), sum(mark) from stu where rollno>1 group by gender


having sum(mark)>100;

instr(name,’a’) sum(mark)

5 260.25

2 146.75

You might also like