Filtrar múltiples criterios

SQL intermedio con IA

Jasmin Ludolf

Senior Data Science Content Developer

Filtrar múltiples criterios

Filtrar por múltiples criterios como géneros de libros y fechas de lanzamiento

SQL intermedio con IA

Todos los requisitos son verdaderos

Instrucción: Muestra películas en inglés de menos de 90 minutos lanzadas después de 1990

SELECT title, release_year, duration
FROM films
WHERE release_year > 1990
AND language = 'English'
AND duration < 90;
|title                   |release_year|duration|
|------------------------|------------|--------|
|Showdown in Little Tokyo|1991        |79      |
|Stone Cold              |1991        |88      |
|Teenage Mutant Ninja ...|1991        |88      |
...
SQL intermedio con IA

O bien

Instrucción: Muestra películas en inglés o francés lanzadas después de 1990

SELECT title, release_year, language 
FROM films
WHERE (language = 'English' OR language = 'French') AND release_year > 1990;
|title                   |release_year|language|
|------------------------|------------|--------|
|Beastmaster 2: Throug...|1991        |English |
|Bill & Ted's Bogus Jo...|1991        |English |
|Boyz n the Hood         |1991        |English |
...
SQL intermedio con IA

Paréntesis

SELECT title, release_year, language 
FROM films
WHERE language = 'English' OR language = 'French' AND release_year > 1990;
|title              |release_year|language|
|-------------------|------------|--------|
|The Broadway Melody|1929        |English |
|Hell's Angels      |1930        |English |
|A Farewell to Arms |1932        |English |
|42nd Street        |1933        |English |
...
SQL intermedio con IA

Rangos de datos

Instrucción: Muestra títulos de películas y año de lanzamiento entre 1990 y 1999

SELECT title, release_year
FROM films
WHERE release_year BETWEEN 1990 AND 1999;
|title                      |release_year|
|---------------------------|------------|
|Arachnophobia              |1990        |
|Back to the Future Part III|1990        |
...
  • Equivalente a release_year >= 1990 AND release_year <= 1999
SQL intermedio con IA

Verificar múltiples valores

Instrucción: Muestra títulos de películas y país para películas de Japón, Italia o España

SELECT title, country
FROM films
WHERE country = 'Japan' OR country = 'Italy' OR country = 'Spain';
|title                         |country|
|------------------------------|-------|
|Seven Samurai                 |Japan  |
|A Fistful of Dollars          |Italy  |
|The Good, the Bad and the Ugly|Italy  |
...
SQL intermedio con IA

Verificar múltiples valores

Instrucción: Muestra títulos de películas y país para películas de Japón, Italia o España

SELECT title, country
FROM films
WHERE country IN ('Japan', 'Italy', 'Spain');
|title                         |country|
|------------------------------|-------|
|Seven Samurai                 |Japan  |
|A Fistful of Dollars          |Italy  |
|The Good, the Bad and the Ugly|Italy  |
...
SQL intermedio con IA

Excluir múltiples valores

Instrucción: Muestra títulos de películas y idioma excepto las que están en inglés y francés

SELECT title, language
FROM films
WHERE language NOT IN ('English', 'French')';
|title        |language|
|-------------|--------|
|Metropolis   |German  |
|Pandora's Box|German  |
|Seven Samurai|Japanese|
...
SQL intermedio con IA

Verificar filtros complejos

$$

  • AND: requiere múltiples condiciones

  • OR: acepta alternativas

  • BETWEEN: rangos

  • IN / NOT IN: múltiples valores

  • Paréntesis para agrupar condiciones y controlar la lógica

IA en una computadora

SQL intermedio con IA

¡Vamos a practicar!

SQL intermedio con IA

Preparing Video For Download...