Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries.

Similar presentations


Presentation on theme: "Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries."— Presentation transcript:

1 Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries.

2 Statement of Truth (Not!) The statement is the foundational basis for logic. Is the statement TRUE or FALSE? Cat = Black Bike = Red TRUE FALSE

3 Statement of Truth (Not!) Evaluations can also be based on numerical values: NumCat = 1 NumBike < 1 TRUE FALSE

4 We know its value, now what? Statement can be combined using the following conjunctions: AND OR NOT Others…

5 AND Truth Table XY X AND Y False TrueFalse True FALSE FALSE FALSE TRUE

6 OR Truth Table XY X OR Y False TrueFalse True FALSE TRUE TRUE TRUE

7 NOT Truth Table X NOT X False True TRUE FALSE

8 Other Truths NAND = NOT AND: (Inverts AND result) NOR = NOT OR: (Inverts OR result) XOR : True if only one operator is true

9 Conditionals How to compare to values.

10 Conditional Statements Equal Not Equal Greater Than Less Than Greater or Equal Than Lesser or Equal Than Like = “≠” > < >= “≥” <= “≤” Like

11 = > < >= <= Like X = 4 X 9 Y > 2 X < 1 Bazillion X >= 4 Y <= 7 Z Like “Do%” Conditional Statements Set Values: X=4 Y=5 Z=“Dog”

12 Examples

13 Example 1: (Cat = Black) AND (Bike = Red) FALSE

14 Example 2: (Cat = Yellow) OR (NumBike > 1) FALSE

15 Example 3: (Cat <> Grey) OR (Bike = Green) TRUE

16 Example 4: (NumCat <= 2) AND (Bike = Blue) TRUE

17 Example 5: NOT (Cat Like “Ca%”) FALSE

18 Example 6: NOT ((Cat < 10) AND (Bike Like “Blu%)) OR ((Cat <= Dog) OR (Bike = Blue)) TRUE

19 Basic SQL Statement

20 Bare Minimums SELECT fieldname 1, fieldname 2,...fieldname n FROM tablename

21 Adding Conditionals SELECT fieldname 1, fieldname 2,...fieldname n FROM tablename WHERE fieldname conditional value (logic_operand fieldname conditional value...)

22 Adding Sort Values SELECT fieldname 1, fieldname 2,...fieldname n FROM tablename WHERE (fieldname conditional value) logic_operand (fieldname conditional value) … ORDER BY fieldname

23 SQL Statement Examples

24 Generic Report 2 SELECT RequestNumber, ResourceName AS Name, Agency, KindCode AS Kind, Trainee as T, UnitID, CheckinDate, CheckinTime FROM vBasicRpts WHERE kindcode like 'hc%' or kindcode = 'cc' ORDER BY RequestNumber

25 Crew Query SELECT RequestNumber, ResourceName AS Crew FROM vBasicRpts WHERE Status <> 'D' AND Agency = 'BIA' and KindCode in ('HC1', 'HC2')

26 Personnel Count by Agency SELECT Agency, COUNT(*) AS [Agency Count], SUM(NumberPersonnel) AS NumberPersonnel FROM vBasicRpts GROUP By Agency

27 DIVS Checkin SELECT ResourceName, CheckinDate FROM vBasicRpts WHERE KindCode = 'DIVS' and CheckinDate between '05/15/07' and '05/20/07' ORDER BY ResourceName


Download ppt "Basic Logic, SQL Statements AND/OR You A quick tour of basic logic and how to evaluate logical expressions and implement simple SQL queries."

Similar presentations


Ads by Google