# Complex Conditions. Logical Operators: AND, OR, NOT AND Cond1Cond2Cond1 AND Cond2T TF FTF OR Cond1Cond2Cond1 OR Cond2T TF FTF NOT CondNOT Cond T F.

## Presentation on theme: "Complex Conditions. Logical Operators: AND, OR, NOT AND Cond1Cond2Cond1 AND Cond2T TF FTF OR Cond1Cond2Cond1 OR Cond2T TF FTF NOT CondNOT Cond T F."— Presentation transcript:

Complex Conditions

Logical Operators: AND, OR, NOT AND Cond1Cond2Cond1 AND Cond2T TF FTF OR Cond1Cond2Cond1 OR Cond2T TF FTF NOT CondNOT Cond T F

Examples Write a complex condition for: 12 <= Age <= 65 Use a complex condition to describe age not between 12 and 65. X <= 15 is equivalent to: X<15 AND X =15? (T/F)

More Complex Conditions University admission rules: Applicants will be admitted if meet one of the following rules: – 1. Income >= 100,000 – 2. GPA > 2.5 AND SAT > 900 An applicants Income is 150,000, GPA is 2.9 and SAT is 800. Admitted? – Income >= 100,000 OR GPA > 2.5 AND SAT >900 How to evaluate this complex condition? – AND has higher priority

Scholarship: Business students with GPA at least 3.2 and major in Accounting or CIS qualified to apply: – 1. GPA >= 3.2 – 2. Major in Accounting OR CIS Is this complex condition correct? – GPA >= 3.2 AND Major = Acct OR Major = CIS – Try: A CIS student with GPA=2.0 Need parenthesis, ( ) – GPA >= 3.2 AND (Major = Acct OR Major = CIS )

Order of Evaluation 1. () 2. And 3. Or

Entering Complex Condition StudentTable: SID, Sname, Major, Sex, FID, GPA Major = CIS and Sex=F Major = CIS OR Sex=F Major=CIS AND GPA>2.5 OR Major=Acct AND GPA>2.7 GPA>2.5 OR Major=CIS AND Sex=F (GPA>2.5 OR Major=CIS) AND Sex=F (Major=CIS AND GPA>3.0 OR Major=Acct) AND Sex=F

Entering Complex Condition Customer Table: CID, Cname, City, Rating Rating=A AND City=SF Rating=A OR City=SF Rating = A OR Rating = B AND City=SF

Employee Table: EmpID, EMpName, Sex, Race, BirthDate, HireDate, Salary, Dept (Sex = Female OR Dept=A) AND Race = Hispanic (Sex = Male OR Sex=male OR Salary>50000) AND Race = Asian (Sex = Male OR Sex=male AND Salary>50000) AND Race = Asian Sex = Female Or Sex=male AND Race = Hispanic OR Dept = A