Sunteți pe pagina 1din 7

Q.What Is Sql ?

A. Sql Is A programming Language With Which All Programes And Users Can Access The
Database.
Q.Diffenent Types Of Sql Statements ?
A. 1)DDL-Used To Define And Manage The Data Structure In The Database.
2)DML-Used To Manipulate The Data InThe Table’s.
3)Transaction Control – Used To Manage Changes Made By The DML Statements.
4)Session Contol (or) DCL-Dinamacally Manages The Properties Of The User Session.
Queries ?
• How To Display Annual Salary Of All Employees?
SQL> select last_name,salary,salary*12
from employees;

• Using Column Aliases?


SQL> select last_name,salary,salary*12 as “Annual Salary”
From employees;

• Using Literals?
SQL> select last_name||'is a'||job_id as "employees details"
from employees;

• How To Combine Two Or More Columns?


SQL> select last_name||Job_id "Employee Details"
From employees;

• To See All The Department_id Without Duplicate?


We Can Use “DISTINCT”
SQL> select distinct department_id
from employees;
• How To Applay Distinct For Multipul Columns?
SQL> select distinct last_name,salary
from employees;

COMPARISON OPERATORS
= Equal To
> Greater Than
>= Greater Than Or EqualTo
< Less Than
<= Less Than Or EqualTo
<> Not Equal To
Between Between Two Values
...and...
IN(set) Match Any Of The List
Value
Like Match The Charactor
Pattern
IsNull Is a Null Value

7)Write A Queri To See All Employees Last_name And Salary How’s Salary Is <= to 3000?
SQL> select last_name,salary
from employees
where salary<=3000;

8) Write A Queri Using Between Operator To Show All The Employees Last_name And Salary
Who’s Salary Is >2000 And <5000?

SQL> select last_name,salary


from employees
where salary between 2000 and 5000;

9) Write A Queri To Show Employee Last_Name Who’s First Letter Is Between K and N?

SQL> select last_name


from employees
where last_name between 'K' and 'N';
10) Using Date Function Search Last _name?

SQL>select last_name
from employees
where hire_date='17-jun-03';

11) How To Use “IN” Operator?

SQL>select last_name,salary,manager_id
from employees
where manager_id in(100,101,201);

12)Write A Queri To Display All Employees First_name Starts With Letter “S” ?

NOTE : % zero Or More Characters


_One Character

SQL>select first_name
from employees
where first_name like 'S%';

Desc : Display All Employees


First_name Second Letter Start
With “o”
(OR)
SQL> select first_name
from employees
where first_name like '_o%';

13) Write A Queri To Show All Employees Who Dont Have Commission?

SQL> select last_name,job_id,commission_pct


from employees
where commission_pct is null;

LOGICAL OPERATORS
AND
OR
NOT

14) Write A Queri To See All The Employee Who’s Working As Manager And Their Salary Must
Me More Than 10,000?

SQL> select * from employees


where salary>=10000
and job_id like '%MAN%';
15) Write A Queri To all The Employees Who Is Working As Manager Or Who’s Salary Is More
Than 10,000?

SQL>select * from employees


where salary>=10000
or job_id like '%MAN%';

16) Write To Show All The Employees Last_name And Job_id Excluding The Managesr’s?
SQL>select last_name,job_id
from employees
where job_id not in ('MAN');

17) Write A Queri To Show last_name,department_id,salary And Condotion Is Department_id Must Be


60,80 And Salary Must Ne More Than 10,000?

SQL>select last_name,department_id,salary
from employees
where department_id=60
or department_id=80
and salary>10000;

Rules Of Precedence
ORDER OPERATOR
1 Arithmetic operators
2 Concatenation
operator
3 Comparison conditions
4 Is [NOT]NULL, LIKE,
[NOT]IN
5 [NOT] Between
6 Not equal to
7 Not logical operator
8 And logical operator
9 Or logical operator

Note : Use Parantesis to Override Rules Of Precedence


Example : select last_name,department_id,salary
from employees
where (department_id=60 Select’s First
or department_id=80)
and salary>1000;

Shorting Of Data
18) Write A Queri To Show All Employees Detail In Assending Order?

SQL>select * from employees


order by employee_id;

19) Write a queri to show all Employees Details In dessending Order?

SQL>select * from employees


order by employee_id desc;

19)Write A queri To Display All Emp Annual Salary In Assending Order Using Column Alias?

SQL>select last_name,salary,salary*12 as Annual_salary


from employees
order by annual_salary desc;

20)Write A Quri To Sort Data By specifying A Numaric Position of a column?

SQL>select last_name,salary,department_id
from employees
order by 3;
21) Write A queri To Show All Employess Department_id In Assending Order And Salary In Descending
Order?

SQL>select * from employees


order by department_id,salary desc;

22) Write A Queri To Prompt The User To Add A New Colum And Also Order By The Column Which The
User Enter’s?

SQL>select last_name,salary,&enter_columnname
from employees
order by &enter_columnname;

Using Functions

Single Row Functions : Return One Result Per Row.


Multiple-Row Functions : Return One Result Per Set Of Row’s.

Case-Conversion Functions:1)Lower 2) Upper 3)Initcap

1) Lower Case : Convert Mixed Case Or Upper Case Charactors Strings To Lower Case.

2) Upper Case : Converts Mixed Case Or Upper Case Charactors String To Upper Case.

3)Initcap : Converts The First Letter Of Each Word To Upper Case And The Remainig Letters To lower
Case.

Examples:

1) SQL>select last_name,employee_id,salary
from employees
where lower(last_name)='higgins';

2) To Display The Name In Upper Case Use The Funcion Upper In Select Clause?

SQL>select upper(last_name),employee_id,salary
from employees
where lower(last_name)='higgins';

Charactor-Mauipulation Functions
You Can Use This Functions To Manipulate The Charactor Strings.

1) Concate : Is Use To Join Two Values Together [Note : Limited To Use Two Parameters].
2)Substring : Extracts A String Of The Length As Specified As An Argument.
3)Length : Shows The Length Of A String As A Numaric Value.
4) Instring : Finds The Numaric Position Of A name Charactor.
5)Lpad : Returns An Expression Left Padded To Length of N charactors With The Charactor
Expression.
6)Rpad : Returns An Expression Right Padded To The Length Of N Charactors With The
Charactop Expression

how to use a replace function


1)write a queri to deplay length and excluding the spaces and calculate only the string length?
a)select length(replace('noor mohammd',' ','')) from dual;

S-ar putea să vă placă și