0% found this document useful (0 votes)
27 views

Consultas Con Agrupamiento: SELECT COUNT (Commission - PCT) FROM Employees WHERE Department - Id 80

This document discusses various Oracle SQL queries using aggregation functions and grouping. It covers using aggregation functions like AVG, MAX, MIN, SUM, and COUNT to retrieve aggregated values from the EMPLOYEES table. It also covers more advanced grouping concepts like grouping by multiple columns, restricting rows using HAVING, and nested aggregation functions. The document provides examples of both legal and illegal uses of aggregation and grouping.

Uploaded by

ManuelRomulo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Consultas Con Agrupamiento: SELECT COUNT (Commission - PCT) FROM Employees WHERE Department - Id 80

This document discusses various Oracle SQL queries using aggregation functions and grouping. It covers using aggregation functions like AVG, MAX, MIN, SUM, and COUNT to retrieve aggregated values from the EMPLOYEES table. It also covers more advanced grouping concepts like grouping by multiple columns, restricting rows using HAVING, and nested aggregation functions. The document provides examples of both legal and illegal uses of aggregation and grouping.

Uploaded by

ManuelRomulo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Consultas con Agrupamiento Talleres Oracle

CONSULTAS CON AGRUPAMIENTO


----------------------------------
-- 1. AVG , MAX, MIN , SUM
----------------------------------
SELECT AVG(SALARY), MAX(SALARY), MIN(SALARY), SUM(SALARY)
FROM EMPLOYEES
WHERE JOB_ID LIKE '%REP%';

SELECT MIN(HIRE_DATE), MAX(HIRE_DATE)


FROM EMPLOYEES;

----------------------------------
-- 2. COUNT
----------------------------------
SELECT COUNT(*)
FROM EMPLOYEES
WHERE DEPARTMENT_ID = 50;

SELECT COUNT(commission_pct)
FROM employees
WHERE department_id = 80;

----------------------------------
-- 3. DISTINCT
----------------------------------
SELECT COUNT(DISTINCT DEPARTMENT_ID)
FROM EMPLOYEES;

----------------------------------
-- 4. USO DE FUNCIONES DE AGRUPAMIENTO Y NULOS
----------------------------------
SELECT AVG(COMMISSION_PCT)
FROM EMPLOYEES;

SELECT AVG(NVL(COMMISSION_PCT, 0))


FROM EMPLOYEES;

----------------------------------
-- 5. GROUP BY
----------------------------------
SELECT DEPARTMENT_ID, AVG(SALARY)
FROM EMPLOYEES
GROUP BY DEPARTMENT_ID ;

INSTRUCTOR : ALAIN MEJIA AVALOS [email protected]


Consultas con Agrupamiento Talleres Oracle

SELECT DEPARTMENT_ID, JOB_ID, SUM(SALARY)


FROM EMPLOYEES
WHERE DEPARTMENT_ID > 40
GROUP BY DEPARTMENT_ID, JOB_ID
ORDER BY DEPARTMENT_ID;

----------------------------------
-- 6. ILEGALES QUERYS
----------------------------------
SELECT DEPARTMENT_ID, COUNT(LAST_NAME)
FROM EMPLOYEES;

SELECT DEPARTMENT_ID, JOB_ID, COUNT(LAST_NAME)


FROM EMPLOYEES
GROUP BY DEPARTMENT_ID;

SELECT DEPARTMENT_ID, AVG(SALARY)


FROM EMPLOYEES
WHERE AVG(SALARY) > 8000
GROUP BY DEPARTMENT_ID;

----------------------------------
-- 7. RESTRINGIENDO FILAS EN AGRUPAMIENTO
----------------------------------
SELECT DEPARTMENT_ID, MAX(SALARY)
FROM EMPLOYEES
GROUP BY DEPARTMENT_ID
HAVING MAX(SALARY)>10000 ;

SELECT JOB_ID, SUM(SALARY) PAYROLL


FROM EMPLOYEES
WHERE JOB_ID NOT LIKE '%REP%'
GROUP BY JOB_ID
HAVING SUM(SALARY) > 13000
ORDER BY SUM(SALARY);

----------------------------------
-- 8. FUNCIONES DE AGRUPAMIENTO ANIDADAS
----------------------------------
SELECT MAX(AVG(SALARY))
FROM EMPLOYEES
GROUP BY DEPARTMENT_ID;

INSTRUCTOR : ALAIN MEJIA AVALOS [email protected]

You might also like