SECTION 5 L1 - Group By and Having Clauses

Similar documents
Intermediate SQL: Aggregated Data, Joins and Set Operators

Using the Set Operators. Copyright 2004, Oracle. All rights reserved.

Using the Set Operators. Copyright 2006, Oracle. All rights reserved.

EXISTS NOT EXISTS WITH

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Laborator 5 Instrucțiunile repetitive

DUE: 9. Create a query that will return the average order total for all Global Fast Foods orders from January 1, 2002, to December 21, 2002.

Database Foundations. 6-4 Data Manipulation Language (DML) Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Alkérdések II. Copyright 2004, Oracle. All rights reserved.


Manipulating Data. Copyright 2004, Oracle. All rights reserved.

KORA. RDBMS Concepts II

Retrieving Data from Multiple Tables

What Are Group Functions? Reporting Aggregated Data Using the Group Functions. Objectives. Types of Group Functions

Utilizarea formularelor in HTML

Restricting and Sorting Data. Copyright 2004, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

ÇALIŞMA TEST SORULARI

HR Database. Sample Output from TechWriter 2007 for Databases

Join, Sub queries and set operators

Database Programming with SQL

School of Computing and Information Technology Session: Spring CSCI835 Database Systems (Bridging Subject) Sample class test 23 July 2018

CONFIGURAREA UNUI SERVER IRC IN LINUX. Bica Bogdan *

DEFAULT Values, MERGE, and Multi-Table Inserts. Copyright 2009, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2004, Oracle. All rights reserved.

Bsc (Hons) Software Engineering. Examinations for / Semester 1. Resit Examinations for BSE/15A/FT & BSE/16A/FT

Fişiere in C++ Un fişier este o colecţie de date indicat printr-un nume şi o extensie. Numele este desparţit de extensie prin punct.

Understanding GROUP BY and how ROLLUP/CUBE functions work

Laborator 8 Java Crearea claselor de obiecte. Variabilele (campurile) clasei de obiecte

Lenuta Alboaie Reţele de calculatoare

Additional Practice Solutions

Rezolvarea exceptiilor

Course Overview. Copyright 2010, Oracle and/or its affiliates. All rights reserved.

Reporting Aggregated Data Using the Group Functions. Copyright 2004, Oracle. All rights reserved.

Retrieving Data Using the SQL SELECT Statement. Copyright 2009, Oracle. All rights reserved.

Data Manipulation Language

Limit Rows Selected. Copyright 2008, Oracle. All rights reserved.

Táblák tartalmának módosítása. Copyright 2004, Oracle. All rights reserved.

1. Să se determine de câte ori apare cifra c în scrierea în baza p a numărului n.

SELF TEST. List the Capabilities of SQL SELECT Statements

School of Computing and Information Technology. Examination Paper Autumn Session 2017

Fisa de lucru: Studiul componentelor calculatorului

1Z0-007 ineroduction to oracle9l:sql

Proiectarea Rețelelor 32. Controlul modelelor de trafic in retea prin alterarea atributelor BGP

Sun Certified MySQL Associate

CHAPTER. Advanced Queries

Tehnici avansate de programare

Ingineria Sistemelor de Programare. UML Diagrama Cazurilor de Utilizare 2016

Se cer 2 variante: una cu implementarea statica si a doua cu implementarea dinamica a structurilor de date necesare. Comentati variantele.

RETRIEVING DATA USING THE SQL SELECT STATEMENT

Database Programming with PL/SQL

Oracle Database SQL Basics

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

CS 275 Winter 2011 Problem Set 3

INDEX. 1 Basic SQL Statements. 2 Restricting and Sorting Data. 3 Single Row Functions. 4 Displaying data from multiple tables

Appendix B: Table Descriptions

Alocarea memoriei în C sub Linux

Database Programming with SQL

Design activities. Session III. 1. Topology. - Selecting and placing devices - Interconnecting devices

Database Programming with SQL

PNI SmartCAM. versiune Android. - manual de utilizare-

Aggregate Functions. Eng. Mohammed Alokshiya. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Dept. Database Lab (ECOM 4113)

Instructiuni de control

insert update delete INSERT, UPDATE DELETE

Laborator 10. SGBD-ul MySQL (partea I)

LECTURE10: DATA MANIPULATION IN SQL, ADVANCED SQL QUERIES

Lecture10: Data Manipulation in SQL, Advanced SQL queries

Using DbVisualizer Variables

CONCAT SUBSTR LOWER (*) All three will be evaluated simultaneously. Correct

Introducere in Maven. Information Type: Working Standard, Disclosure Range:, Information Owner: mihai.hulea, NTT DATA Romania

Proiectarea bazelor de date

Oracle Database 10g: SQL Fundamentals II

Exam: 1Z Title : Introduction to Oracle9i: SQL. Ver :

Memorator funcţii predefinite C++ Funcţii matematice

Série n 6 Bis : Ateliers SQL Data Modeler (Oracle)

Rezolvare fişă de laborator Java Iniţiere în limbajul Java

Ingineria Sistemelor de Programare

Assignment Grading Rubric

Oracle9i: Advanced SQL

Îmbunătăţiri aduse în limbajul C++ facilităţilor standard ale limbajului C (cele care nu ţin de conceptele programării orientate obiect).

Testing Masters Technologies

Exam : 1Z Title : Introduction to Oracle9i: SQL

Creating Other Schema Objects

Introduction to Oracle9i: SQL

Oracle Database: SQL Fundamentals I. Oracle Internal & Oracle Academy Use Only. Volume II Student Guide. D64258GC10 Edition 1.0 January 2010 D65028

2. What privilege should a user be given to create tables? The CREATE TABLE privilege

RMOUG Training Days 2018

GIFT Department of Computing Science. CS-217/224: Database Systems. Lab-5 Manual. Displaying Data from Multiple Tables - SQL Joins

Database Programming with SQL

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Database Programming with PL/SQL

Probleme propuse pentru Testul de Laborator Semestrul I

Operatii pop si push-stiva

Database Foundations. 6-9 Joining Tables Using JOIN. Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Lucrarea nr. 2. Funcţii şi structuri în C++

Oracle Database 10g: SQL Fundamentals II


1. Funcţii referitoare la o singură înregistrare (single-row functions)

Database Programming with SQL

Transcription:

SECTION 5 L1 - Group By and Having Clauses Clauza Group By 1. SELECT department_id, AVG(salary),MAX(salary) 2. SELECT job_id, last_name, AVG(salary) GROUP BY job_id; ORA-00979: not a GROUP BY expression 3. SELECT count(first_name), shirt_color FROM students GROUP BY shirt_color 4. WHERE last_name <> King 5. SAU SELECT count(*), shirt_color FROM students GROUP BY shirt_color SELECT AVG(media), specializare FROM studenti WHERE data-absolvire >= 01-JUN-2010 GROUP BY specializare; 6. SELECT COUNT(prenume), an_studiu FROM studenti GROUP BY an_studiu;

In clauza SELECT putem avea: - Functii de grup ( dar nu statistice) - Cimpuri ( care trebuie sa apara si in clauza GROUP BY) Clauza WHERE : Filtreaza inregistrarile asupra carora va actiona SELECT Clauza GROUP BY: - Nu poate contine alias de cimp/coloana Grupuri si subgrupuri (maxim 2) SELECT department_id, job_id, count(*) WHERE department_id > 40 GROUP BY department_id, job_id; Clauza Having Doar grupurile ce respecta conditia mentionata in clauza HAVING vor fi returnate WHERE COUNT(*) > 1 ORA-00934: group function is not allowed here HAVING COUNT(*) >1; Ordinea clauzelor in instructiunea SELECT: SELECT column, group_function FROM table WHERE GROUP BY HAVING ORDER BY

SECTION 5, L2 extensii ale clauzei GROUP BY: Rollup - genereaza subtotaluri la nivel de grup si un total general SELECT department_id, job_id, SUM(salary) GROUP BY ROLLUP (department_id, job_id) Cube genereaza rapoarte cross-tabulate ( la nivel de subgroup / grup /raport) SELECT department_id, job_id, SUM(salary) GROUP BY CUBE (department_id, job_id) GROUPING SETS similar cu utilizarea mai multor clause GROUP BY in aceeasi instructiune SELECT. SELECT department_id, job_id, manager_id, SUM(salary) GROUP BY GROUPING SETS ( (job_id, manager_id), (department_id, job_id), (department_id, manager_id)); 1 2 3 Functia GROUPING(coloana/cimp), utilizata in clauza SELECT Furnizeaza 2 valori: - 1 daca in inregistrarea returnata coloana/cimpul este calculate - 0 in cazul unui cimp simplu

SELECT department_id, job_id, SUM(salary), GROUPING(department_id) Dept_sub_total, GROUPING(job_id) job_sub_total, GROUP BY CUBE (department_id, job_id); SELECT depart_id, job_id, SUM(salary), DECODE(GROUPING(depart_id),1,'DeptAggr row',depart_id) AS DT, DECODE(GROUPING(job_id),1,'JobID Aggr row',job_id) AS JI WHERE depart_id < 50 GROUP BY CUBE (depart_id, job_id);

SELECT cimp1,cimp2 FROM tabel1 <operator> SELECT cimp1,cimp2 FROM tabel2 SECTION 5 L3 operatorii Set UNION, UNION ALL, INTERSECT, MINUS * unde cimp1 si cimp2 trebuie sa fie de acelasi tip si acelasi nume in ambele tabele SELECT department_name "Department", TO_CHAR(NULL) "Warehouse" FROM departments UNION SELECT TO_CHAR(NULL) "Department", warehouse_name FROM warehouses; * clauza ORDER BY poate fi utilizata doar in al 2-lea SELECT SELECT hire_date (1), employee_id (2), to_date(null) start_date (3), to_date(null) end_date (4) UNION SELECT to_date(null )(1),employee_id (2),start_date (3),end_date (4) FROM job_history ORDER BY employee_id;