Ex.
No:
Date :
Implementation basic sql query
Aim:
Problem description:
1. Create a table Employee with the structure :
first_name -varchar, last_name- varchar,age int-department varchar.
2. Display table.
3. Add 7 records
4. Retrieve first_name,last_name,department from employee table
where age>30; 5. insert into table values ('anand','selvan',28,'hr') and
('jansi','rani',32,'finance').
6. Display the table.
7. update the age of the employee jansi rani as 35.
8. Add another record as ('bhavana','v',22,'sales department') and
display.
9. delete from table having department='sales department'
10. display first_name,last_name,department from employee table.
11. Display from employee table where department='hr' and
age>30.
12. Add another record into table ('robert','brown', 45,'hr').
13. Update age of the employee kamal as 34.
Description and syntax:
1. SELECT Query- The SELECT statement is used to retrieve data from
a database. It can
be used to fetch specific columns or all columns from a table.
Syntax: SELECT column1, column2, ...
FROM table_name;
2. WHERE Clause- The WHERE clause is used to filter records based
on specific
conditions. It’s commonly used in combination with the SELECT,
UPDATE, or DELETE
statement.
Syntax: SELECT column1, column2, ...
FROM table_name
WHERE condition;
3. INSERT INTO Query- The INSERT INTO statement is used to add
new rows of data
into a table.
Syntax: INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
4. UPDATE Query- The UPDATE statement is used to modify existing
records in a table.
Syntax: UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition
Code and output:
SQL> create table cricket (first_name varchar(20), last_name
varchar(20),age number(12),team varchar(12));
Table created.
SQL> insert into cricket values('ms','dhoni',45,'csk');
1 row created.
SQL> insert into cricket values('rohit','sharma',43,'mi');
1 row created.
SQL> insert into cricket values('virat','kholi',39,'rcb');
1 row created.
SQL> insert into cricket values('risab','phant',30,'dc');
1 row created.
SQL> insert into cricket values('kl','rahul',28,'punjab');
1 row created.
SQL> insert into cricket values('sai','sudharsan',27,'gujarat');
1 row created.
SQL> insert into cricket values('ruturaj','gaikwad',27,'csk');
1 row created.
SQL> select*from cricket;
7 rows selected.
SQL> select first_name,last_name,team from cricket where age>30;
SQL> update cricket set age=28 where last_name='gaikwad';
1 row updated.
SQL> delete from cricket where last_name='gaikwad';
1 row deleted.
SQL> select*from cricket;
6 rows selected.
SQL> select*from cricket where team='csk';
1 row selected
SQL> update cricket set team='gujarat' where last_name='rahul';
1 row updated.
SQL> select*from cricket;
6 rows selected.
SQL> select last_name from cricket;
6 rows selected.
Result:
Ex.No:
Date :
Implementation of SQL clauses
AIM:
PROBLEM DESCRIPTION:
1.create table with IT_Projects
structure:project_name,team_lead,team_size,technology,status,salary.
2. add 4 records the name from the tables.
3. select the name from the tables.
4. insert team_project_name-smartcityportal,lead-sameem,technology-
cloud,,status-in progress,salary-80000.
5. Display table
6. choose a distinct technology from the table.
7. Display all team_lead from It_projects table.
8. Divide salary from by 5 from the table and display it.
9. display team_lead from table having technology=ai.
10.insert the another value project_name-ai_assistant,team_lead-
anas,technology-ai,status-completed,salary-75000.
11.display name from table who’s salary is null.
12.change the table name It_projects to project_progress.
13.display the team_lead from the table where technology in
cybersecurity.
14.display the team_lead where team_size between 5 and 7.
15 display the technology where team_lead like iot.
16.display the table order by team_lead.
17.select team_lead,technology,salary from table-group by salty.
18.dispaly the team_size,salary group by salary and having count
(team_size>5).
DESCRIPTION AND SYNTAX:
SELECT CLAUSE: The select clause lists the attributes desired in the
result of a query corresponds to the projection operation of the relational
algebra.
SYNTAX: SELECT column1, column2, ... FROM table_name;
DISTINCT CLAUSE: - SQL allows duplicates in relations as well as in
query results. To force the elimination of duplicates, insert the keyword
distinct after select. SYNTAX: SELECT DISTINCT column1, column2, ...
FROM table_name;
ARITHMETIC EXPRESSIONS IN SELECT CLAUSE: - The select
clause can contain arithmetic expressions involving the operation, +, –,
*, and /, and operating on constants or attributes of tuples.
SYNTAX: Select [arithmetic operator]…
FROM [Table name] WHERE [expression];
WHERE CLAUSE: - The where clause specifies conditions that the
result must satisfy Corresponds to the selection predicate of the
relational algebra.
SYNTAX: SELECT column1, column2, ...
FROM table_name
WHERE condition From CLAUSE: - The from clause lists the relations
involved in the query Corresponds to the Cartesian product operation of
the relational algebra.
SYNTAX: SELECT CustomerName, City FROM Customers;
NULL VALUE: - It is possible for tuples to have a null value, denoted by
null, for some of their attributes null signifies an unknown value or that a
value does not exist.
SYNTAX: SELECT column_names FROM table_name WHERE
column_name IS NULL;rename operation-
CLAUSES OF THE SELECT STATEMENT:
(i)IN - command allows you to specify multiple values in a WHERE
clause.
SYNTAX: SELECT column_name(s) FROM table_name WHERE
column_name IN (value1, value2, ...);
(ii) BETWEEN - operator selects values within a given range. The values
can be nUmbers, text, or dates.
SYNTAX: SELECT column_name(s) FROM table_name
WHERE column_name BETWEEN value1 AND value2;
(iii)LIKE - Indicate the table(s) or view(s) from which data will be
obtained
SYNTAX: SELECT column1, column2, ...
FROM table_name WHERE columnN LIKE pattern;
(iv)ORDER BY - Sorts the result according to specified criteria
SYNTAX:- SELECT column1, column2, ...
FROM table_name ORDER BY column1, column2, ... ASC|DESC;
(v)GROUP BY Indicate categorization of results
SYNTAX: SELECT column_name(s)FROM table_nameWHERE
condition
GROUP BY column_name(s);
(vi)HAVING-Indicate the conditions under which a category will be
included.
SYNTAX: SELECT column_name(s)FROM table_name WHERE
condition GROUP BY column_name(s)HAVING condition
ORDER BY column_name(s);
CODE AND OUTPUT:
create table it_projects(project_name varchar(20),team_lead
varchar(20),team_size int,tech varchar(20),salary int);
SQL>desc it_projects;
SQL>insert into it_projects
values(‘samrtcityportal’,’sameem’,’cloud’,80000);
SQL>insert into it_projects values(‘ai_asisstant’,’basith’,’ai’,75000);
SQL>insert into it_projects
values(‘healthtrack’,’davidmiller’,’iot’,50000);
SQL>insert into it_projects
values(‘visonanaltics’,’abdullah’,’cloud’,80000);
SQL>select team_lead from it_projects;
SQL>select*from it_projects;
SQL>insert into it_projects values(‘ai_assistant’,’anas’,’ai’,70000);
SQL>select*from it_projects;
SQL>select distinct tech from it_projects;
SQL>select all team_lead from it_projects;
SQL>select salary/5 from it_projects;
SQL>select team_lead from it_projects where tech=’ai’;
SQL>select*from it_projects;
SQL>insert into it_projects values(‘healthtrack’,’maya’,’iot’,50000);
SQL>select from it_projects where salary is null;
SQL>rename it_projects to project_progress;
SQL>select*from project_progress;
SQL>select team_lead from project_progress where team_lead
in(‘sameem’,’basith’,’anas’)’;
SQL>select*from project_progress where salary between 50000
and 80000;
SQL>select*from project_progress where tech like ‘iot’;
Ex.No:
Date :
Implementation of Scalar and
Aggregate Function
SQL>select*from project_progress order by team_lead;
SQL>select (count) salary from projrct_prgress group by salary;
Select count(salary) from project_progress group by team_lead
having count(salary)>20000;
Result:
Aim:
Problem Description:
1. Create a table with structure.
2. Add a 5 records and display the table.
3. Round the attributes of the table and retrieve the attributes from
table.
4. Uppercase the attributes and retrieve from table.
5. Lowercase the attributes and retrieve from table.
6. Display the length of the attributes from the table.
7. Display the first 3 character of the attributes of the table using
substrings .
8. Select the minimum number of the attributes.
9. Select the maximum number of the attributes and count,sum and
average the attributes from the table.
Code and output:
SQL> create table bank(branch varchar(20),ifsc_code int,location
varchar(12));
Table created.
SQL> desc bank;
SQL> insert into bank values ('iob',123,'chennai');
1 row created.
SQL> insert into bank values ('kanara',456,'kerala');
1 row created.
SQL> insert into bank values ('kvb',376,'singapore');
1 row created.
SQL> insert into bank values ('indianbank',867,'coimbatore');
1 row created.
SQL> select * from bank;
SQL> select branch,location,round(ifsc_code,2)roundedifsc from bank;
SQL> select upper(location)uppercaselocation,branch from bank;
SQL> select lower(location)lowercaselocation,branch from bank;
SQL> select ifsc_code,branch,length(branch) as branchlength from
bank;
SQL> select ifsc_code,branch,substr(location,1,4) as locationsubstring
from bank;
SQL> select min(ifsc_code) from bank;
SQL> select max(ifsc_code) from bank;
SQL> select count(ifsc_code) from bank;
SQL> select sum(ifsc_code) from bank;
SQL> select avg(ifsc_code) from bank;
Result: