You are on page 1of 14

Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

ACTIVITY #1 -MIDTERM PERIOD Logical Operators

Name: Kier Christian F, Reyes Date Submitted: April 09, 2024


Section: 2CS-A Submitted to: Marvin Bicua
ACTIVITY #1 -MIDTERM PERIOD LINK:
https://drive.google.com/drive/folders/1usNyul4WYkbkuayFwQmLB5tfghIpE3pm?usp=sharing.

I. Create Table that has text and numeric values.


Code ScreenShots (I use MEDIUMINT only since numbers that ranges to 8
million only for the zipcode and UNSIGNED also since I don’t need negative
numbers for my order_id).
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

Code ScreenShots
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

Code Output
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

Sample Code
CREATE TABLE orderTally
(order_Id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_Fullname VARCHAR(50) NOT NULL,
sex ENUM('M', 'F') NOT NULL,
city VARCHAR (40) NOT NULL,
zip MEDIUMINT UNSIGNED NOT NULL,
phone VARCHAR(20) NOT NULL,
item_purchased VARCHAR(30) NOT NULL,
item_cost FLOAT NULL,
date_purchased TIMESTAMP
);

DESCRIBE orderTally;
INSERT INTO orderTally(customer_Fullname, sex, city, zip,
phone, item_purchased, item_cost, date_purchased) VALUES
('Addisyn Santiago', 'F', 'Albuquerque', 87101, 946984,
'iPhone 15 Plus', 899.00, NOW()),
('Valentino Stuart','F', 'San Francisco', 94107, 293764,
'iPhone SE', 429.00, NOW()),
('Katie Prince', 'F', 'Detroit', 48204, 738654, 'iPhone 14',
699.00, NOW()),
('Alejandro Noble', 'M', 'Salt Lake City', 84102, 103453,
'iPhone 15 Pro Max', 1599.00, NOW()),
('Hailey Herrera', 'F', 'Jersey City' , 07032, 983201,
'iPhone 15', 799.00, NOW()),
('Dane Lam', 'M', 'Oakland' , 94505, 543421, 'iPhone 15 Pro',
999.00, NOW()),
('Maximo Burns', 'M', 'Kansas City', 64109, 843512, 'iPhone
13', 599, NOW()),
('Zaylee Bradshaw', 'F', 'Detroit', 48206, 732145, 'iPhone 14
Plus', 799.00, NOW()),
('Royal Paul', 'M', 'San Francisco', 94108, 287546, 'iPhone
15 Pro', 999.00, NOW()),
('Ainsley Dominguez', 'F', 'Kansas City', 64106, 874352,
'iPhone 14', 699.00, NOW()),
('Peyton Lang', 'F', 'Oakland', 94509, 546732, 'iPhone 15',
799.00, NOW()),
('Addisyn Santiago', 'F', 'Jersey City', 07032, 342154,
'iPhone SE', 429.00, NOW()),
('Valentino Stuart', 'F', 'Albuquerque', 87103, 946537,
'iPhone SE', 429.00, NOW());
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

II. Display Tables using Logical Operators.

Code ScreenShots
o Using ‘AND’ and ‘OR’

o Using ‘AND’ and ‘NOT’

o Using ‘XOR’ and ‘NOT’ (exclusive or returns the reverse of AND and
NOT in the above, since both conditional statements are true (If both
T = F).
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

Code Output
o USING ‘AND’ and ‘OR’

o Using ‘AND’ and ‘NOT’

o Using ‘XOR’ and ‘NOT’ (exclusive or returns the reverse of AND and
NOT in the above, since both conditional statements are true (If both
T = F).
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

Sample Code
SELECT customer_Fullname, item_purchased, item_cost FROM
orderTally
WHERE (city = 'Albuquerque' OR city = 'Salt Lake City') AND
(item_cost < 2699.00 AND item_cost > 399.00) ORDER BY
item_cost DESC;

SELECT customer_Fullname, city, item_purchased, item_cost


FROM orderTally
WHERE NOT city = 'Kansas City' AND NOT item_purchased =
'iPhone SE' ORDER BY item_cost DESC;

SELECT customer_Fullname, city, item_purchased, item_cost


FROM orderTally
WHERE NOT city = 'Kansas City' XOR NOT item_purchased =
'iPhone SE' ORDER BY item_cost DESC;
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

Post activity questions

Using the tables that was created from the previous activity, use IN and
BETWEEN combine with the AND, OR and NOT Operator.
o Using ‘IN’ and ‘AND’ (It ignores the other Valentino that is duplicate since it
only retrieves zip codes that starts with value 9);

o Using ‘IN’ and ‘OR’ (At least one needs to be true so this returns the first
condition output.)
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

o Using ‘IN’ and ‘NOT’

o Using ‘BETWEEN’ and ‘AND’


Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

o Using ‘BETWEEN’ and ‘OR’

o Using ‘BETWEEN’ and ‘NOT’


Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

Sample Code
-- USING IN and AND
SELECT customer_Fullname, item_purchased, item_cost FROM
orderTally
WHERE city IN ('Oakland', 'San Francisco') AND zip LIKE '9%';
-- USING IN and OR
SELECT customer_Fullname, item_purchased, item_cost, zip FROM
orderTally
WHERE city IN ('Kansas City', 'Salt Lake City') OR item_cost
>= 1000;

-- USING IN and NOT


SELECT customer_Fullname, item_purchased, item_cost, zip FROM
orderTally
WHERE city NOT IN ('Albuquerque', 'San Francisco', 'Oakland')
AND item_cost < 2000;

-- USING BETWEEN and AND


SELECT customer_Fullname, item_purchased, item_cost, zip FROM
orderTally
WHERE item_cost BETWEEN 100 AND 1000 AND item_purchased =
'iPhone 15 Pro';

-- USING BETWEEN and OR


SELECT customer_Fullname, item_purchased, item_cost, zip FROM
orderTally
WHERE item_cost BETWEEN 500 AND 2000 OR item_purchased =
'iPhone 14';

-- USING BETWEEN and NOT


SELECT customer_Fullname, item_purchased, phone, zip FROM
orderTally
WHERE phone NOT BETWEEN 874352 AND 946984 AND item_purchased
= 'iPhone SE';
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

Sample Code (Full Code)


CREATE DATABASE lgOperators;

USE lgOperators;

CREATE TABLE orderTally


(order_Id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_Fullname VARCHAR(50) NOT NULL,
sex ENUM('M', 'F') NOT NULL,
city VARCHAR (40) NOT NULL,
zip MEDIUMINT UNSIGNED NOT NULL,
phone VARCHAR(20) NOT NULL,
item_purchased VARCHAR(30) NOT NULL,
item_cost FLOAT NULL,
date_purchased TIMESTAMP
);

DESCRIBE orderTally;

INSERT INTO orderTally(customer_Fullname, sex, city, zip,


phone, item_purchased, item_cost, date_purchased) VALUES
('Addisyn Santiago', 'F', 'Albuquerque', 87101, 946984,
'iPhone 15 Plus', 899.00, NOW()),
('Valentino Stuart','F', 'San Francisco', 94107, 293764,
'iPhone SE', 429.00, NOW()),
('Katie Prince', 'F', 'Detroit', 48204, 738654, 'iPhone 14',
699.00, NOW()),
('Alejandro Noble', 'M', 'Salt Lake City', 84102, 103453,
'iPhone 15 Pro Max', 1599.00, NOW()),
('Hailey Herrera', 'F', 'Jersey City' , 07032, 983201,
'iPhone 15', 799.00, NOW()),
('Dane Lam', 'M', 'Oakland' , 94505, 543421, 'iPhone 15 Pro',
999.00, NOW()),
('Maximo Burns', 'M', 'Kansas City', 64109, 843512, 'iPhone
13', 599, NOW()),
('Zaylee Bradshaw', 'F', 'Detroit', 48206, 732145, 'iPhone 14
Plus', 799.00, NOW()),
('Royal Paul', 'M', 'San Francisco', 94108, 287546, 'iPhone
15 Pro', 999.00, NOW()),
('Ainsley Dominguez', 'F', 'Kansas City', 64106, 874352,
'iPhone 14', 699.00, NOW()),
('Peyton Lang', 'F', 'Oakland', 94509, 546732, 'iPhone 15',
799.00, NOW()),
('Addisyn Santiago', 'F', 'Jersey City', 07032, 342154,
'iPhone SE', 429.00, NOW()),
('Valentino Stuart', 'F', 'Albuquerque', 87103, 946537,
Republic of the Philippines

University of Cabuyao
'iPhone SE', 429.00, NOW());
(Pamantasan ng cabuyao)
SELECT customer_Fullname, item_purchased,
COLLEGE OF COMPUTING STUDIESitem_cost FROM
orderTally
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025
WHERE (city = 'Albuquerque' OR city = 'Salt Lake City') AND
(item_cost < 2699.00 AND item_cost > 399.00) ORDER BY
item_cost DESC;

SELECT customer_Fullname, city, item_purchased, item_cost


FROM orderTally
WHERE NOT city = 'Kansas City' AND NOT item_purchased =
'iPhone SE' ORDER BY item_cost DESC;

SELECT customer_Fullname, city, item_purchased, item_cost


FROM orderTally
WHERE NOT city = 'Kansas City' XOR NOT item_purchased =
'iPhone SE' ORDER BY item_cost DESC;

-- USING IN and AND


SELECT customer_Fullname, item_purchased, item_cost FROM
orderTally
WHERE city IN ('Oakland', 'San Francisco') AND zip LIKE '9%';
-- USING IN and OR
SELECT customer_Fullname, item_purchased, item_cost, zip FROM
orderTally
WHERE city IN ('Kansas City', 'Salt Lake City') OR item_cost
>= 1000;

-- USING IN and NOT


SELECT customer_Fullname, item_purchased, item_cost, zip FROM
orderTally
WHERE city NOT IN ('Albuquerque', 'San Francisco', 'Oakland')
AND item_cost < 2000;

-- USING BETWEEN and AND


SELECT customer_Fullname, item_purchased, item_cost, zip FROM
orderTally
WHERE item_cost BETWEEN 100 AND 1000 AND item_purchased =
'iPhone 15 Pro';

-- USING BETWEEN and OR


SELECT customer_Fullname, item_purchased, item_cost, zip FROM
orderTally
WHERE item_cost BETWEEN 500 AND 2000 OR item_purchased =
'iPhone 14';

-- USING BETWEEN and NOT


SELECT customer_Fullname, item_purchased, phone, zip FROM
orderTally
WHERE phone NOT BETWEEN 874352 AND 946984 AND item_purchased
= 'iPhone SE';
Republic of the Philippines

University of Cabuyao
(Pamantasan ng cabuyao)
COLLEGE OF COMPUTING STUDIES
Katapatan Mutual Homes, Brgy. Banay-banay, City of Cabuyao, Laguna 4025

You might also like