0% found this document useful (0 votes)
3 views2 pages

Activity1 Batch2

The document outlines SQL commands for creating and managing a database named 'activity1_batch2' and a table called 'staff'. It includes instructions for inserting data, selecting and manipulating data, and performing various calculations on the staff's ages. Additionally, it demonstrates how to group and order the data based on specific criteria.

Uploaded by

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

Activity1 Batch2

The document outlines SQL commands for creating and managing a database named 'activity1_batch2' and a table called 'staff'. It includes instructions for inserting data, selecting and manipulating data, and performing various calculations on the staff's ages. Additionally, it demonstrates how to group and order the data based on specific criteria.

Uploaded by

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

-- 1.

Create the database


CREATE DATABASE activity1_batch2;

-- 2. Use the database


USE activity1_batch2;

-- 3-8. Create the staff table


CREATE TABLE staff (
staff_id VARCHAR(6) PRIMARY KEY,
staff_name CHAR(40),
age INT,
assigned_area VARCHAR(45),
phone_no CHAR(15),
address VARCHAR(55)
);

-- 9. Describe the staff table


DESCRIBE staff;

-- 10. Insert data into the staff table


INSERT INTO staff VALUES ("1", "richard", 12, "wagwagan", "090909090909", "La
Trinidad");
INSERT INTO staff VALUES ("2", "viel", 25, "store", "0987654321", "Baguio");

-- 11. Select all data from the staff table


SELECT * FROM staff;

-- 12. Select the square root of age


SELECT SQRT(age) AS 'output value' FROM staff;

-- 13. Select the modulus of age divided by 2


SELECT MOD(age, 2) AS 'Computed Value' FROM staff;

-- 14. Select the power of age raised to 3


SELECT POWER(age, 3) AS 'Exponent Value' FROM staff;

-- 15. Select the greatest value among age, phone_no, 1, 2, 3, 4, 5


SELECT GREATEST(age, phone_no, 1, 2, 3, 4, 5) AS 'Highest Value' FROM staff; --
Note: phone_no is a string, so greatest function will not compare it numerically.

-- 16. Select the rounded square root of age


SELECT ROUND(SQRT(age), 2) AS 'round value' FROM staff;

-- 17-20. Concatenate staff_name and assigned_area


SELECT staff_name, assigned_area, CONCAT(staff_name, '-', assigned_area) AS
StaffWorkStation FROM staff;

-- 21-25. Select all data and staff_name, ordered by age descending


SELECT *, staff_name FROM staff ORDER BY age DESC;

-- 26. Insert a new record


INSERT INTO staff VALUES ("15569", "Ivan", 35, "Surplus", "09123456789", "");

-- 27-30. Select all data, length of phone_no, and phone_no as contact_info


SELECT *, LENGTH(phone_no), phone_no AS contact_info FROM staff;

-- 31-35. Count the number of staff in each assigned_area


SELECT assigned_area AS 'name_of_areas', COUNT(assigned_area) AS 'count_of_area'
FROM staff GROUP BY assigned_area;
-- 36-40. Select staff_name, assigned_area, and age, ordered by age
SELECT *, staff_name AS 'Name of Staff', assigned_area AS 'Working Area', age AS
'Seniors' FROM staff ORDER BY age;

You might also like