Содержание
- 2. Last lecture AS String Concatenation || DISTINCT IS NULL & IS NOT NULL Range condition: ,
- 3. Aggregate Functions SQL provides the following aggregate functions that appear in SELECT statement: Min() selects the
- 4. Aggregate Functions Example: Select the minimum, maximum and average gpa from the Students table. SELECT min(gpa),
- 5. Aggregate Functions Selecting count(*) or count(expression) returns the number of tuples that satisfy a selection condition.
- 6. Aggregate Functions Example: Get number of students with group_id = 1. The column should be named
- 7. Students table Count (*) Count (group_id) Count example
- 8. GROUP BY The aggregate functions can also be applied to subsets of tables. In SQL, rows
- 9. GROUP BY: example Example: Select the group_id’s that students study in and the number of students
- 10. GROUP BY: example Students table SELECT count(*) FROM Students;
- 11. GROUP BY: example Students table SELECT group_id, count(*) FROM Students GROUP BY group_id;
- 12. HAVING The HAVING clause is used to filtering groups This is similar to a selection condition
- 13. HAVING: example Query the group_id’s and number of students of each group. SELECT group_id, count(*) FROM
- 14. Example with join SELECT g.name as group_name, count(*) as number_of_students FROM Students s, Groups g WHERE
- 15. ORDER BY The ORDER BY clause is used to set the ordering of the resultant table.
- 16. Ordering Results in SQL: example • The ordering of results may be mixed in query: one
- 17. Example with join SELECT g.name as group_name, count(*) as number_of_students FROM Students s, Groups g WHERE
- 18. SELECT Statement SQL allows us to query data using select statements. Syntax: SELECT attribute(s) FROM table(s)
- 19. Complete SELECT Statement SELECT attribute(s) FROM table(s) [WHERE selection condition(s)] [GROUP BY condition(s)] [HAVING condition(s)] [ORDER
- 20. Select Statement Summary
- 21. String Functions and Operators
- 22. String Functions and Operators
- 23. Date Functions EXTRACT (field FROM source) EXTRACT function retrieves subfield such as year or hour from
- 24. Date Functions date_part (‘field’, source) Source must be a value expression of date type. Field is
- 25. Date Functions Fields: century year month week day decade quarter dow (the day of the week)
- 26. EXTRACT / date_part examples SELECT EXTRACT(year FROM bdate) FROM Students; SELECT date_part('year', bdate) FROM Students;
- 27. Date Functions CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP Example: SELECT CURRENT_DATE;
- 29. Скачать презентацию