CLASS XI-XII
(SQL - OPERATORS ASSIGNMENTS)
SQL TUTORIAL
SQL - Operators
·
Arithmetic operators
·
Comparison operators
·
Logical operators
Arithmetic operators:
+ [Addition] - [Subtraction]
/ [Division] * [Multiplication]
% [Modulus]
Example 1SQL> select 10+ 20; |
Output: 30 |
Example 2SQL> select 10 * 20; |
Output: 200 |
Example 3SQL> select 10 / 5; |
Output: 2.0000 |
Example 4SQL> select 12 % 5; |
Output: 2 |
How to use
these operators in a record stored in a tables
Table:
Employee
employee_id
|
employee_name
|
salary
|
1
|
alex
|
25000
|
2
|
rr
|
55000
|
3
|
jpm
|
52000
|
4
|
ggshmr
|
12312
|
Q. To diplay
employee ID,Name,Salary and Annual Salary (salary*12 months) from the table
employee.
Ans:
SELECT employee_id,employee_name,salary,salary*12 FROM employee;
employee_id
|
employee_name
|
salary
|
Salary*12
|
1
|
alex
|
25000
|
300000
|
2
|
rr
|
55000
|
660000
|
3
|
jpm
|
52000
|
624000
|
4
|
ggshmr
|
12312
|
147744
|
A new Field added with new name salary
*12.But salary *12 is not a proper name
it should display the name Annual Salary
Ans:
SELECT
employee_id,employee_name,salary,salary*12 AS “Annual
Salary” FROM employee;
employee_id
|
employee_name
|
salary
|
Annual salary
|
1
|
alex
|
25000
|
300000
|
2
|
rr
|
55000
|
660000
|
3
|
jpm
|
52000
|
624000
|
4
|
ggshmr
|
12312
|
147744
|
Annual salary column name is known a column alias.It give a
table, or a column in a table, a temporary name.
Q. Write a query to
display employee_name,salary,HRA(10% of salary),DA(5% of Salary) and
NETSALARY(Salary+HRA+DA)
To
display a report, showing coachname, pay, age and bonus(15% of pay) for all
coaches.