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 expressions

SQL Lesson 9

Se pueden utilizar expresiones para escribir consultas más complejas, haciendo uso de funciones matemáticas y de cadenas junto con la aritmética básica para transformar valores al ejecutar la consulta.

Las expresiones ahorran tiempo, pero pueden provocar que la consulta sea más difícil de leer, por lo que es recomendable usar un alias descriptivo con AS.

SELECT _col_expression_ AS _expr_description_, … 
FROM mytable;

  1. Listá todas las películas y sus ventas combinadas en millones de dólares.

SELECT title, (domestic_sales+international_sales)/1000000 AS combined_sales
FROM movies
INNER JOIN boxoffice
	ON id=movie_id; 
  1. Lista todas las películas y sus ratings en porcentaje.

SELECT title, rating*10 AS rating_percent
FROM movies
INNER JOIN boxoffice
	ON id=movie_id;
  1. Enumere todas las películas que se estrenaron en años pares.

SELECT title,year
FROM movies
WHERE year%2=0;
PreviousA short note on NULLsNextQueries with aggregates (Pt. 1)

Last updated 1 year ago