SQL Foundations I Module 2

Use AND, OR and comparison operators in WHERE

Only editable by group admins

  • Last updated August 24, 2016 at 1:05 PM
  • Evidence visible to public
Four queries will utilize various predicates involving multiple AND and OR clauses (a minimum of three total), with a variety of comparison operators. Provide a link to your work.

All posted evidence

And OR Whare It all passed!

SELECT * FROM teacher WHERE                 salary > 70000                 AND     (teach_id > 12     OR     salary>100000)   SELECT * FROM student WHERE                 dob < '2000-02-02'                            AND     (student_name like 'J%'     OR     creditsearned >20) 

https://parkland1-my.sharepoint.com/:w:/r/personal/sdow3_stu_parkland_edu/_layouts/15/Doc.aspx?sourcedoc=%7B49198A6F-18AB-40C0-BF1C-94B3CD5DF86B%7D&file=Module%202_%20CSC176%20Data%20Systems_Sharon%20Dow%20102318.docx&action=default&mobileredirect=true
sdow3 About 7 years ago

4 old links plus one query using OR

Query 4

mpurnell1 About 8 years ago

Query 3

mpurnell1 About 8 years ago

Query 2

mpurnell1 About 8 years ago

Query 1

mpurnell1 About 8 years ago

Results of Queries 3&4

jmfisher About 8 years ago

Results of Queries 1&2

jmfisher About 8 years ago

Use of AND, OR, comparisons in WHERE .Decided to include INNER JOINS so that information was more readable rather than just numbers.

/*Query 1 - List those signs that would be considered "Banners" based on dimensions and material*/
SELECT CONCAT(Signs.hor_dimens, ' ft x ', Signs.vert_dimens, ' ft') as 'Banners', Materials.name as 'Material', Finishes.name as 'Finish', Signs.quantity as 'Quantity', Signs.cost as 'Cost'
FROM Signs 
INNER JOIN Materials ON Signs.mat_id=Materials.mat_id
INNER JOIN Finishes ON Signs.finish_id=Finishes.finish_id
WHERE (Signs.hor_dimens>4 or Signs.vert_dimens>4) and Signs.mat_id != 5 and Signs.mat_id != 6;
/*Query 2 - List those signs that would be considered "Posters" based on dimensions and material*/
SELECT CONCAT(Signs.hor_dimens, ' ft x ', Signs.vert_dimens, ' ft') as 'Posters', Materials.name as 'Material', Finishes.name as 'Finish', Signs.quantity as 'Quantity', Signs.cost as 'Cost'
FROM Signs 
INNER JOIN Materials ON Signs.mat_id=Materials.mat_id
INNER JOIN Finishes ON Signs.finish_id=Finishes.finish_id
WHERE (Signs.hor_dimens<4 and Signs.vert_dimens<4) and Signs.mat_id != 5 and Signs.mat_id != 6;
/*Query 3 - List those signs that are printed on adhesive material*/
SELECT CONCAT(Signs.hor_dimens, ' ft x ', Signs.vert_dimens, ' ft') as 'Adhesive Signs', Materials.name as 'Material', Finishes.name as 'Finish', Signs.quantity as 'Quantity', Signs.cost as 'Cost'
FROM Signs 
INNER JOIN Materials ON Signs.mat_id=Materials.mat_id
INNER JOIN Finishes ON Signs.finish_id=Finishes.finish_id
WHERE Signs.mat_id = 5 or Signs.mat_id = 6;
/*Query 4 - List those signs that can be used outside by excluding those with certain materials*/
SELECT CONCAT(Signs.hor_dimens, ' ft x ', Signs.vert_dimens, ' ft') as 'Outdoor Ready', Materials.name as 'Material', Finishes.name as 'Finish', Signs.quantity as 'Quantity', Signs.cost as 'Cost'
FROM Signs 
INNER JOIN Materials ON Signs.mat_id=Materials.mat_id
INNER JOIN Finishes ON Signs.finish_id=Finishes.finish_id
WHERE Signs.mat_id != 4 and Signs.mat_id != 6;
jmfisher About 8 years ago

WHERE the file isn't in my cleanup directory AND the file is between 300 and 500 bytes.

jaco Almost 9 years ago

A few and and or operators manipulating data from the movies table.

SELECT *
FROM countries
WHERE 
	country_name LIKE '%stan%' 
	OR continent == 'AFRICA'
	OR 
		(continent == 'AMERICA' 
		AND country_name != 'United States'
		AND country_name != 'Canada')

SELECT *
FROM movies
WHERE 
	(year_released >= 1990 AND year_released < 2000) 
	AND (country = 'us' OR country = 'uk')

SELECT *
FROM movies
WHERE 
	(title LIKE 'Le %' OR title LIKE 'The %') 
	moAND (country != 'gb' and country != 'au')

SELECT *
FROM movies
WHERE 
	(title LIKE '% 2' OR title LIKE '% 3') 
	AND (country != 'us' AND country != 'gb')
vbecu1 Almost 9 years ago

Narrowed down to a single file with WHERE and AND again.

jaco Almost 9 years ago