stamin4
  • whoami
  • HTB Academy
    • Introduction to Academy
    • Learning Process
    • Vulnerability Assessment
    • Web Requests
    • Introduction to Networking
    • Linux Fundamentals
    • Brief Intro to Hardware Attacks
    • Setting Up
    • Using the Metasploit Framework
    • Security Incident Reporting
    • Introduction to Web Applications
    • JavaScript Deobfuscation
    • Attacking Web Applications with Ffuf
    • Windows Fundamentals
    • File Inclusion
  • HTB Machines
    • Windows
      • 🟢Easy
      • 🟠Medium
      • 🔴Difficult
      • 🟣Insane
    • Linux
      • 🟢Easy
        • Cap
      • 🟠Medium
      • 🔴Difficult
      • 🟣Insane
  • OverTheWire
    • Bandit
      • Nivel 0
      • Nivel 1
      • Nivel 2
      • Nivel 3
      • Nivel 4
      • Nivel 5
      • Nivel 6
      • Nivel 7
      • Nivel 8
      • Nivel 9
      • Nivel 10
  • Base de datos
    • SQL
      • SELECT queries 101
      • Queries with constraints (Pt. 1)
      • Queries with constraints (Pt. 2)
      • Filtering and sorting Query results
      • Simple SELECT Queries
      • Multi-table queries with JOINs
      • OUTER JOINs
      • A short note on NULLs
      • Queries with expressions
      • Queries with aggregates (Pt. 1)
      • Queries with aggregates (Pt. 2)
      • Order of execution of a Query
      • Inserting rows
      • Updating rows
      • Deleting rows
      • Creating tables
      • Altering tables
      • Dropping tables
  • PortSwigger
    • Path Traversal
  • Dockerlabs
    • Trust
    • Firsthacking
    • Upload
Powered by GitBook
On this page
  1. Base de datos
  2. SQL

Queries with aggregates (Pt. 1)

SQL Lesson 10

SELECT AGG_FUNC(column_or_expression) AS aggregate_description, …
FROM mytable
WHERE constraint_expression
GROUP BY column;
Función
Descripción

COUNT (columna)

Cuenta el número de filas de la tabla, o de una columna si es especificada sin contar los valores NULL.

MIN (columna)

Encuentra el menor valor numérico en una columna específica.

MAX (columna)

Encuentra el mayor valor numérico en una columna específica.

AVG (columna)

Encuentra el promedio de valores numéricos en una columna específica.

SUM (columna)

Encuentra la suma de todos los valores numéricos en una columna específica.


  1. Encuentra el tiempo más largo que un empleado ha trabajado en el estudio.

SELECT MAX(years_employed) AS max_years_employed
FROM employees;
  1. Para cada rol, encuentra el promedio de años que llevan los trabajadores empleados.

SELECT role,AVG(years_employed) AS avg_years_employed
FROM employees
GROUP BY role;
  1. Encuentre el número total de años que llevan los empleados trabajando en cada edificio.

SELECT building,SUM(years_employed) AS total_years_employed
FROM employees
GROUP BY building;
PreviousQueries with expressionsNextQueries with aggregates (Pt. 2)

Last updated 1 year ago