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

week -03 dbms

The document outlines a series of SQL queries related to a course database, covering tasks such as displaying course information, updating lab fees, and performing calculations on course data. It includes queries for filtering courses based on various criteria, creating and modifying tables, and aggregating data for analysis. The queries are organized by week, indicating a structured approach to learning SQL operations.

Uploaded by

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

week -03 dbms

The document outlines a series of SQL queries related to a course database, covering tasks such as displaying course information, updating lab fees, and performing calculations on course data. It includes queries for filtering courses based on various criteria, creating and modifying tables, and aggregating data for analysis. The queries are organized by week, indicating a structured approach to learning SQL operations.

Uploaded by

Neeraj Mittal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Week -01

Table creation

Week-02
Q1. Display the entire course table.

Query - select * from minor;

Q2. Display all information about any course with a zero clabfee.

Query - select * from minor where clbfee=0.00;

Q3. Display all information about any course which is offered by the
philosophy department.

Query - select * from minor where cdept=”PHIL”;

Q4. Display all rows where the number of credits exceeds 3.

Query - select * from minor where cred>3;


Q5. Display all information about the RELATIONAL DATABASE course.

Query - select * from minor where name=”RELATIONAL DATABASE”;

Q6. Display the row for course number 18.

Query - select * from minor where cno =8;

Q7. Display all information about courses having cname values which
follow “HEDONISM” in alphabetic sequence.

Query- select * from minor where name=”HEDONISM” order by name


ASC;

Q8. Display the cno, cname, and cdept values (in that order) for every row
in the course table. 9.

Query – select distinct cdept from minor;


Q9. Select the cno, cdept, and clabfee values for every course with a
clabfee value less than $100.

Query- select cno,cdept,clbfee from minor where clbfee<100.00;

Q10.Display the course names of all CIS courses.

Query- select name from minor where cdept =”CIS”;

Q 11. Display every academic department which offers courses.

Query- select cdept from minor ;


Q 12. Display every academic department which offers courses. Do not
display duplicate values.

Query- select distinct cdept from minor ;

Q13.For each course with a lab fee less than $100, display the academic
department which offers the course and the number of awarded credits.

Query- select name, cdept, cred from minor where clbfee < 100;

Q14. Display the course number and name of every course which has a
lab fee over $100. Include a third column in the result table which shows
“EXPENSIVE” in each row.
Query- select cno,name,’EXPENSIVE’ as status from minor where
clbfee>100;
WEEK -03

Q1. Change the lab fee for the course with course number “19” to $175.

Query = update minor SET clbfee = 175 where cno =9;

Q2. Make the following changes to any course:

• Set the credit value to 6

• Increase the lab fee by 10 percent

• Change the description (CDESCP) to “THE LANGUAGE OF SQL”

Query = update minor SET cred=6,c_desc="THE LANGUAGE OF


SQL",clbfee = clbfee*1.10 where cno=1;

Q3. Delete all rows from the COURSE table which have a course number
greater than 23.
Query=DELETE from minor where cno>13;

Q4. Display the CNAME, CNO, CRED, and CLABFEE columns (in that order)
for every row in the table. Sort the displayed rows by CNO within
CLABFEE. (CLABFEE is the major sort field, and CNO is the minor sort
field).

Query= select cno,name,cred,clbfee from minor order by clbfee,cno;

Q5. Display the CDEPT, CLABFEE, and CNAME values of all three credit
courses. Sort the output result. CDEPT is the first-level sort field
(ascending); CLABFEE is the second-level sort field (descending); and
CNAME is the third-level sort field (ascending).

Query = select name,clbfee,cdept from minor order by cdept asc,clbfee


desc,name asc;

Q6. Display all information about any three-credit philosophy course which
has a lab fee strictly between $0 and $100.

Query =select * from minor where cred =3 and clbfee>0 and clbfee<100;
Q7. Display all information about every course offered by the philosophy
or theology department.

Query=select * from minor where cdept="PHIL" or cdept="THEO";

Q8. Display all information about any course which has a lab fee equal to
$50, $100, $150, or $200.

Query=select * from minor where clbfee = 50 or clbfee=100 or


clbfee=150 or clbfee=200;

Q9. Select the CNO, CNAME, and CLABFEE of any course with a lab fee
other than $100.
Query=select cno,name,clbfee from minor where !(clbfee=100);

Q10. Display the name and department identifier of all courses with the
exception of those courses offered by the CIS and PHIL departments.

Query=select name,cdept from minor where!(cdept = "CIS" or


cdept="PHIL");

Q11. Display any information about any theology course which has a zero
lab fee, or any course (regardless of its department and lab fee) which is
worth six credits.

Query=select * from minor where cdept="THEO" and clbfee=0 and


cred=6;
Q12. Display all information about every row in the COURSE table except
any CIS course which has zero lab fee.

Query=select * from minor where not(cdept="CIS" and clbfee=0);

Q13. Display the course number, description, and credits for any course
which is worth two, six, or nine credits.

Query=select cno,c_desc,cdept from minor where cred=2 or cred=6 or


cred=9;

Q14. Display the course name, description, and department identifier of


any course which is not offered by the theology or CIS department.

Query=select cno,c_desc,cdept from minor where !(cdept="THEO" or


cdept="CIS");
Q15. Display the course number and lab fee for any course with a lab fee
between and including $50 and $400.

Query =select cno,clbfee from minor where clbfee>=50 and


clbfee<=400;

Q16. Display the course number and lab fee of any course with a lab fee
which is less than $50 or greater than $400.

Query=select cno,clbfee from minor where clbfee<=50 and clbfee>=400;

Q17. Display the department identifier, course name, and lab fee of any
three-credit CIS, THEO or MGT course with a lab fee between, and
including, $50 and $300. Sort the result by course name within
department identifier sequence (ascending).

Query=select cdept,name,clbfee from minor where cred=3 and


cdept="CIS" or cdept="THEO" or cdept="MGT" and clbfee>50 and
clbfee<300 order by cdept ,name;
WEEK -04

Q1. Display the information about any course which has a description
beginning with the string“FOR THE”.

Query – select * from minor where c_desc like ‘FOR THE%’;

Q2. Display all CNAME values which end with the letters “CISM”.

Query – select * from minor where name like ‘%CISM’;


Q3. What are the names of the courses which have the letters “TA”
appearing anywhere in the name?

Query – select * from minor where name like ‘%TA%’;

Q4. Display the course number and description of any course with a
period, hyphen, or exclamation mark anywhere in its description.

Query – select cno,c_desc from minor where c_desc like '%!%' or c_desc
like '%-%' or c_desc like '%.%';

Q5. Display the department identifier of any course where the department
identifier ends with “IL”.Do not display duplicate values.

Query – select cdept from minor where cdept like ‘%IL’;

Q6. Display the course name and department identifier of any course
which has the letter “H” present in the second position of its department
identifier and is exactly four characters long.
Query – select name,cdept from minor where cdept like ‘_H__’ and
length(cdept)=4;

Q7. Display the names of courses which have a vowel as the second letter
of their name.

Query - select name from minor where name like '_A%' or name like '_E%'
or name like '_I%' or name like '_O%' or name like '_U%';

Q8. Display the name and description of any course where the description
has “THE” in the fifth, sixth, and seventh positions, and “A” in the tenth
position.

Query - select name,c_desc from minor where c_desc like '____THE__A%';


Q9. Display the names of all courses which do not have a vowel as the
second letter of their name.

Query - select name from minor where !(name like '_A%' or name like '_E
%' or name like '_I%' or name like '_O%' or name like '_U%');

Q10. Display the course name and description of any course which does
not end with an “E” or an“S”.

Query – select name,c_desc from minor where !(name like '%E' or name
like '%S');

Q11. Create a table Person with PersonID as the primary key.


Query –

1.) CREATE TABLE Person ( PersonID INT PRIMARY KEY,LastName


VARCHAR(100), FirstName VARCHAR(100), Age INT);

2.) CREATE TABLE Orders ( OrderID INT PRIMARY KEY, OrderNumber INT,
PersonID INT);

Q12. Create a FOREIGN KEY constraint on the PersonID column when the
Orders table is already created.

Query -ALTER TABLE Orders ADD CONSTRAINT fk_person FOREIGN KEY


(PersonID) REFERENCES Person(PersonID);

Q13. Insert at least 5 records into the Person table and 3 records into the
Orders table.

Query –

INSERT INTO Person (PersonID, LastName, FirstName, Age) VALUES

(1, 'Alice', 'Sharma', 23),

(2, 'Bob', 'Kumar', 21),

(3, 'Charlie', 'Raj', 23),

(4, 'David', 'Ram', 25),

(5, 'Emma', 'Kishore', 22);

INSERT INTO Orders (OrderID,OrderNumber,PersonID) VALUES

(1,77895,3),

(2,44678,3),

(3,22456,2),

(4,24562,1);
Q14, Drop the Foreign Key from the Orders table.

Query - ALTER TABLE Orders DROP CONSTRAINT fk_person;

Week -05

Q1. Suppose that we are interested in the impact of increasing the lab fee
charges for all CIS courses. What would be the lab fee for each CIS course
if its lab fee were increased by $25? Display each CIS course name
followed by the current lab fee and the adjusted lab fee.

Query - select name,clbfee as prevLabfee,clbfee+25 as currlabfee from


minor where cdept = "CIS";
Q2. For each philosophy course, divide the credits in half. Display the
course name, credits, and the result of dividing the credits in half.

Query - select name, cred as prevCred,cred/2 as currCred from minor


where cdept = "PHIL";

Q3. What would be the lab fee of a theology course if each such course
were charged $10.50 per credit? Display the course number and the
adjusted lab fees of all theology courses.

Query - select name , cred*10.50 as currFee from minor where cdept =


"THEO";

Q4. What is the average lab fee per credit hour for courses offered by the
CIS department?

Query - select avg(clbfee/cred) as abg_lab_fee_per_credit from minor


where cdept="CIS";
Q5. For any course with a lab fee less than $200, display its course
number and its adjusted lab fee which is $35 more than 150 % of the
current lab fee.

Query - select cno ,(clbfee*1.5)+35 as adjusted_lab_fee from minor where


clbfee<200;

Q6. Which CIS courses have an average lab fee per credit hour value
greater than $30?

Query - select name from minor where (clbfee/cred)>30 and cdept="CIS";

Q7. What is the average lab fee for all courses described in the course
table?

Query - select avg(clbfee) from minor;


Q8. Consider only rows for the philosophy department. What are the
lowest and highest lab fees for these courses? Also, what are the lowest
and highest values in the CNO column?

Query - select min(clbfee) as min_clbfee,max(clbfee) as


max_clbfee,min(cno) as min_cno,max(cno) as max_cno from minor where
cdept="PHIL";

Q9. What is the sum of all the lab fee values for CIS courses?

Query - select sum(clbfee) as sum_of_clbfee from minor where


cdept="CIS";

Q10. How many theology courses are recorded in the COURSE table?

Query -select count(*) as theo_courses from minor where cdept ="THEO";

Q11. Display the average, maximum, and minimum course lab fees for
those CIS courses which have non-zero lab fee.
Query - select avg(clbfee) as avg_clbfee,max(clbfee)as max_clbfee,
min(clbfee) as min_clbfee from minor where cdept="CIS" and clbfee>0;

Q12. 12. Display the variance and standard deviation of all the course lab
fees in the COURSE table.

Query - SELECT VARIANCE(clbfee) AS variance_lab_fee, STDDEV(clbfee) AS


stddev_lab_fee FROM minor;

Q13. Display two values. The first is the sum of all lab fees assuming each
has been increased by $25. The second is the result of adding $25 to the
sum of all the lab fees.

Query - select sum(clbfee+25) as sum_increased, sum(clbfee)+25 as


sum_addition from minor;

Q14. For each department which offers courses, determine the average
lab fee of all three-credit courses offered by the department. Display the
output in ascending sequence by department identifier.

Query - SELECT cdept, AVG(clbfee) AS avg_lab_fee FROM minor WHERE


cred = 3 GROUP BY cdept ORDER BY cdept;
Q15. Do not consider six-credit course. For each department which offers
courses, display the department identifier followed by the total of the lab
fees for courses offered by the department.Sort the result by the total lab
fee in descending sequence.

Query - SELECT cdept, SUM(clbfee) AS total_lab_fees FROM minor WHERE


cred != 6 GROUP BY cdept ORDER BY total_lab_fees DESCv;

Q16. For each distinct lab fee value, determine the total number of credits
for courses having this lab fee value. Sort the result by lab fee in
descending order.

Query - SELECT clbfee, SUM(cred) AS total_credits FROM minor GROUP BY


clbfee ORDER BY clbfee DESC;

Q17. For each department which offers six-credit courses, display the
average lab fee of the six-credit courses.

Query -SELECT cdept, AVG(clbfee) AS avg_lab_fee FROM minor WHERE


cred = 6 GROUP BY cdept;
Q18. Display the department identifier and average lab fee for any
department where that average exceeds $100.

Query - SELECT cdept, AVG(clbfee) AS avg_lab_fee FROM minor GROUP BY


cdept HAVING avg_lab_fee > 100;

Q19. For every department, except the theology department, which has
an average lab fee of $100,display its department identifier followed by its
average lab fee.

Query - SELECT cdept, AVG(clbfee) AS avg_lab_fee FROM minor WHERE


cdept != 'THEO' GROUP BY cdept HAVING avg_lab_fee = 100;

Q20. Retrieve the average, maximum, and minimum lab fee values by
credit within a department only for those groups which have a maximum
lab fee value greater than zero.

Query - SELECT cdept, cred, AVG(clbfee) AS avg_lab_fee, MAX(clbfee) AS


max_lab_fee, MIN(clbfee) AS min_lab_fee FROM minor GROUP BY cdept,
cred HAVING MAX(clbfee) > 0;
Q21. What is the average department lab fee value for those departments
where this average is

greater than $100 and the department offers less than six courses?

Query - SELECT cdept, AVG(clbfee) AS avg_lab_fee FROM minor GROUP BY


cdept HAVING avg_lab_fee > 100 AND COUNT(*) < 6;

You might also like