SQL - SELECT - WHERE
SQL - SELECT - WHERE
USE DATASTORE
--Write a SQL stattemet to read data from table for all columns
SELECT *
FROM employee
--Write a SQL code to read data form table with specific columns
SELECT
EmployeeNo,
Ename,
Job,
DepartmentNo,
Salary
FROM employee
--Write a SQL statement to read data from employee if the employees are woring in
department number 10
--WHERE: It is used to restrict the data based on on condition
--Condition always returns TRUE or FALSE
--We can frame the condition by using the following syntax
--syn: columnName<operator>value
SELECT *
FROM employee
WHERE DepartmentNo=10
--Write a SQL Statement to read data from employee, if the employees are getting more
than 2000 salary
SELECT *
FROM employee
WHERE Salary>2000
--Write a SQL Statement to read data from employee, if the employees are getting less
than 2000 salary
SELECT *
FROM employee
WHERE Salary<2000
--Wriate SQL Statement to get employee details, if the employees working in Department
10 or Department 20
SELECT *
FROM employee
WHERE DepartmentNo=10 OR DepartmentNo=20
/*
To join multiple conditions, then we have to use Logical OR operator or Logical AND
operator
Syn: Condition-1 OR/AND Condition-2
Logical OR: If business requirement demands to satisfy either one of the condition,
then we can use Logical OR operator
Logical AND: If business requirement demands to satisfy both of the conditions, then
we can use Logical AND operator
*/
--Write a SQL statement to get employee details, if the employee are working as
Salesman or working in department 20
--Note: Strings will be enclosed in single(') quotes
SELECT *
FROM employee
WHERE Job='Salesman' OR DepartmentNo=20
--Write a SQL Statement to get employee details, if the employee are getting less than
2000 in the department 30
SELECT *
FROM employee
WHERE Salary<2000 AND DepartmentNo=30
--Write a SQL Statement to get employee details if the employees are getting Salary
from 2000 to 3000
SELECT *
FROM employee
WHERE Salary>=2000 AND Salary<=3000
SELECT *
FROM employee
WHERE Salary BETWEEN 2000 AND 3000
--Wriate SQL Statement to bring data from employee, if the employees are join in 2023-
04-02 date
SELECT *
FROM employee
WHERE Hiredate = '2023-04-02'
--Write a SQL statement to bring data from employee, if the employees are joined in
the year of 2023
SELECT *
FROM employee
WHERE Hiredate >= '01-01-2023' AND Hiredate<='12-31-2023'
--Write a SQL Statement to bring data employee if the employees are joined in the
month of September 2023
--Write a SQL Statement to bring employee data if the employees are not joined in the
month of September 2023
--Write a SQL Statement to bring employee details if the employees are not eligible
for commission
SELECT *
FROM employee
WHERE Commission IS NULL
/*
******************************************************************
Functions
******************************************************************
Functions are used to handle Numbers, Text and Date and Time
There are few categories of the Functions
1. Numeric Functions
2. String Functions
3. Date & Time Functions
4. Aggregate Functions
5. Windows Functions
Numeric Functions:
1. ABS(<Number>): Returns the absolute value of a number
*/
/*
ROUND(<Number>, <No: Of Decimal Places>) : It is used to round a number to a specified
number of decimal places.
Ex: 10.5
10--> Main Number
.5--> Decimal Number
*/
SELECT 1/2.0
SELECT
EmployeeNo,
Ename,
Job,
Salary,
Salary/3.5 AS NewSalary,
ROUND(Salary/3.5, 2) AS RundedSalary
FROM employee