You are on page 1of 7

I18303 -RELATIONAL DATABASE

MANAGEMENT SYSTEM
UNIT – 3
STRING OPERATIONS, AGGREGATE
FUNCTIONS & VIEWS
String operations
UPPER
• Select upper (information) as ‘upper’;
INFORMATION
LOWER
• Select lower (INFORMATION) as ‘lower’;
information
SUBSTRING
• Select substring (“helloworld”, 1, 5);
hello
REPLACE
• Select REPLACE('123geeks123', '123','');
geeks
String operations
REVERSE
• Select REVERSE('geeksforgeeks.org');
gro.skeegrofskeeg
RIGHT
• Select RIGHT('geeksforgeeks.org', 4);
.org
LEFT
• Select LEFT('geeksforgeeks.org', 5);
geeks
Aggregate functions
These functions are used to do operations from the values of the
column and a single value is returned.
• AVG()
• COUNT()
• MAX()
• MIN()
• SUM()
Aggregate functions
AVG()
• It returns average value after calculating from values in a numeric column
Select AVG(marks) As AvgMarks from Student;
COUNT()
• It is used to count the number of rows returned in a SELECT statement.
Select COUNT(*) As NumOfStudents from Student;
MAX()
• It returns the maximum value of the selected column.
Select MAX(marks) As MaximumMark from Student;
MIN()
• It returns the minimum value of the selected column.
Select MIN(marks) As MinimumMark from Student;
SUM()
• It returns the sum of all values of the selected column.
Select SUM(marks) As TotalMarks from Student;
Views
• In SQL, a view is a virtual table based on the result-set of an SQL
statement.
• A view contains rows and columns, just like a real table.
• The fields in a view are fields from one or more real tables in the
database.
Create View :Syntax
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
CREATE VIEW

Student table 

CREATE VIEW MechStudents AS


SELECT Rollno, Name, Dept
FROM Student
WHERE Dept = ‘MECH';

You might also like