0% found this document useful (0 votes)
4 views6 pages

DBMS 4

The document contains SQL queries for creating and managing an employee database, including creating tables, inserting employee records, and retrieving specific employee information based on salary and hire date. It also demonstrates typecasting salary values and categorizing employees based on their hire dates. Various SQL commands are provided for data manipulation and retrieval tasks.

Uploaded by

nkindia0891
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

DBMS 4

The document contains SQL queries for creating and managing an employee database, including creating tables, inserting employee records, and retrieving specific employee information based on salary and hire date. It also demonstrates typecasting salary values and categorizing employees based on their hire dates. Various SQL commands are provided for data manipulation and retrieval tasks.

Uploaded by

nkindia0891
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

PROGRAM -4

❖ Query : Create a employee table and find the employee_id , name


and salary whose salary is greater than 15000.
• Input :
CREATE TABLE employees(

employee_id INT PRIMARY KEY ,

first_name VARCHAR(50) ,

salary INT);

INSERT INTO employees(employee_id,first_name,salary) VALUES

(100,'Steven',24000),

(101,'Neena',17000),

(102,'Lex',17000),

(103,'John',11000),

(104,'Robert',12000),

(105,'Leo',10000);

SELECT employee_id,first_name,salary FROM employees

WHERE salary > 15000;

SELECT employee_id,first_name,salary FROM employees

WHERE salary > '15000';


❖ Query : Create a Employee Table.
• Input :
CREATE TABLE EMPLOYEE (

EMPLOYEE_ID INT PRIMARY KEY,

FIRST_NAME VARCHAR(50),

LAST_NAME VARCHAR(50),

HIRE_DATE DATE);

INSERT INTO EMPLOYEE (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, HIRE_DATE) VALUES

(1, 'John', 'Doe', '2024-08-26'),

(2, 'Jane', 'Smith', '2024-08-27'),

(3, 'Michael', 'Johnson', '2024-08-28'),

(4, 'Emily', 'Brown', '2024-08-29'),

(5, 'David', 'Lee', '2024-08-30'),

(6, 'Sarah', 'Garcia', '2024-08-31'),

(7, 'Robert', 'Wang', '2024-09-01'),

(8, 'Lisa', 'Patel', '2024-09-02');

SELECT * FROM EMPLOYEE;

❖ Query : Find the hire date of employee whose last name is ‘Doe’.
• Input :
SELECT EMPLOYEE_ID, FORMAT(HIRE_DATE, 'YYYY-MM-DD') AS MONTH_HIRED

FROM EMPLOYEE

WHERE LAST_NAME = 'Doe';


• Input :
SELECT FORMAT(HIRE_DATE, 'YYYY-MM-DD') AS FORMATTED_DATE FROM EMPLOYEE;

❖ Query : Insert details of two new employees.


• Input :
INSERT INTO EMPLOYEE (EMPLOYEE_ID, LAST_NAME, HIRE_DATE)

VALUES (9, 'Doe', '2024-08-26'),(10, 'Smith', '2024-08-27');

• Input :
SELECT COALESCE(FIRST_NAME, 'Unknown') AS EMPLOYEE_NAME FROM EMPLOYEE;
❖ Query : Divide the employees as early hire and recent hire based on
their hire date.
• Input :
SELECT

EMPLOYEE_ID,

FIRST_NAME,

LAST_NAME,

CASE

WHEN HIRE_DATE < '2024-09-01' THEN 'Early Hire'

ELSE 'Recent Hire'

END AS HIRE_CATEGORY

FROM EMPLOYEE;
• Input :
SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, FORMAT(HIRE_DATE, '%Y-%m-%d') AS
HIRE_DATE_STRING FROM EMPLOYEE;

• Input :
SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, FORMAT(HIRE_DATE, 'YYYY-MM-DD') AS
HIRE_DATE_STRING FROM EMPLOYEE;

❖ Query : Typecast salary as integer type.


• Input :
SELECT EMPLOYEE_ID, FIRST_NAME, CAST(SALARY AS INT) AS INTEGER_SALARY FROM Employees;
❖ Query : Typecast salary as variable type.
• Input :
SELECT EMPLOYEE_ID, FIRST_NAME, CAST(SALARY AS VARCHAR) AS VARCHAR_SALARY FROM
EMPLOYEES;

• Input :
SELECT CAST(SALARY AS '$99,999.00') AS INTEGER_SALARY FROM EMPLOYEES;

• Input :
SELECT CAST('2022-04-01' AS DATE);

• Input :
SELECT CONVERT(int, 25.65);

You might also like