Presentation is loading. Please wait.

Presentation is loading. Please wait.

From 10th Edition and 8th Edition

Similar presentations


Presentation on theme: "From 10th Edition and 8th Edition"— Presentation transcript:

1 From 10th Edition and 8th Edition
MORE SQL From 10th Edition and 8th Edition

2 WHERE clause can refer to a set of values WHERE <attribute> IN
(value1, value2,…) 2

3 WILDCARDS SELECT * FROM <table>
WHERE <attribute> LIKE ‘xxx*’; Note: * stands for any sequence of characters in Access. WHERE <attribute> LIKE ‘*xxx*’; 3

4 CALCULATIONS SELECT SUM (<attribute>)
FROM <table>; -- not so good NOTE: n-a-n stands for new attribute name In these notes (but not in Access) a – at the end of a query is to be interpreted as a comment about the query. (courtesy T. Weber) SELECT SUM (<attribute>) AS <n-a-n> FROM <table>; better FROM <table> WHERE <attribute> <rel-op> <value>;

5 More Built-In Calculators
SELECT AVG(<attribute>) AS <n-a-n> FROM <table>; SELECT MIN(<attribute>) AS < n-a-n > SELECT MAX(<attribute>) AS < n-a-n >

6 More Built-In Calculators
SELECT COUNT(*) AS <n-a-n> FROM <table>; SELECT COUNT(<attribute>) AS <n_a_n> SELECT COUNT( DISTINCT <attribute>) AS <n_a_n>

7 Other possibilities missing values are looked for using IS NULL
single column sorting is done using ORDER BY multiple column sorting is done using ORDER BY <attribute1, attribute2, …> 7

8 SQL Arithmetic SELECT <attribute1> * <attribute2> AS <n-a-n> FROM <table>; SELECT <attribute1> * <attribute2> AS <n-a-n>, <attribute> 8

9 SQL Arithmetic SELECT <attribute1> + ‘in’ + <attribute2> AS <n-a-n>FROM <table>; SELECT DISTINCT RTRIM(<attribute1>) + ‘in’ + RTRIM(<attribute2>) AS <n-a-n> FROM <table>; 9

10 GROUPING SELECT <attribute>, COUNT (*) AS <n-a-n>
FROM <table> GROUP BY <attribute>; SELECT <attribute1>, AVG<attribute2> AS <n-a-n>

11 GROUPING SELECT <attribute1>, <attribute2> , COUNT (*) AS <n-a-n> FROM <table> GROUP BY <attribute1>, <attribute2>; SELECT <attribute> COUNT(*) AS <n-a-n> WHERE <attribute ><rel-op> <value> GROUP BY <attribute> ORDER BY <n-a-n>

12 MULTI-TABLE QUERIES SELECT SUM<attribute1> AS <n-a-n>
FROM <table1> WHERE <attribute2> IN (value1, value2,…valueN); SELECT <attribute2 > FROM <table2> WHERE <attribute3> <rel-op> <value>;

13 MULTI-TABLE QUERIES SELECT SUM<attribute1> AS <n-a-n>
FROM <table1> WHERE attribute2 IN (SELECT <attribute2 > FROM <table2> WHERE <attribute3> <rel-op> <value>;

14 JOINS SELECT * FROM <table1>, <table2>;
WHERE <table1.attribute> <rel-op> <table2.attribute>


Download ppt "From 10th Edition and 8th Edition"

Similar presentations


Ads by Google