MySQL Filtering and Aggregating
10 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Use the ______________ statement to get all the columns from a table.

SELECT *

The __________________ clause is used to group rows that have the same values in one or more columns.

GROUP BY

The __________________ operator is used to select a range of values.

BETWEEN

The __________________ clause is used to filter records and fetch only those that meet certain conditions.

<p>WHERE</p> Signup and view all the answers

The __________________ function is used to count the number of rows in a table.

<p>COUNT</p> Signup and view all the answers

Use the __________________ clause to get rows where values in a group meet a criterion.

<p>HAVING</p> Signup and view all the answers

The __________________ operator is used to select rows where a column is one of several values.

<p>IN</p> Signup and view all the answers

Use the __________________ wildcard to select rows where a column contains specific letters.

<p>LIKE</p> Signup and view all the answers

The __________________ clause is used to get summaries grouped by values in a specific order.

<p>GROUP BY ... ORDER BY</p> Signup and view all the answers

Use the __________________ statement to get a column from a table by name.

<p>SELECT col</p> Signup and view all the answers

Study Notes

Filtering Data

  • Filter on numeric columns using WHERE clause with operators: &gt;, &gt;=, &lt;, &lt;=, !=
  • Example: SELECT franchise, inception_year FROM franchises WHERE inception_year &gt; 1928

Aggregating Data

  • Use aggregate functions: COUNT(*), SUM(col), AVG(col), MIN(col), MAX(col)
  • Example: SELECT COUNT(*) FROM franchises
  • Group data using GROUP BY clause
  • Example: SELECT owner, COUNT(*) FROM franchises GROUP BY owner

Querying Tables

  • Retrieve all columns using SELECT *
  • Retrieve specific columns using SELECT col1, col2
  • Use FROM clause to specify table name
  • Example: SELECT franchise, inception_year FROM franchises

Filtering on Text Columns

  • Filter on text columns using WHERE clause with operators: =, IN, LIKE
  • Example: SELECT franchise, original_medium FROM franchises WHERE original_medium = 'book'
  • Use LIKE operator with wildcard % to match patterns
  • Example: SELECT franchise, original_medium FROM franchises WHERE original_medium LIKE '%oo%'

Grouping and Filtering

  • Use HAVING clause to filter groups
  • Example: SELECT original_medium, SUM(n_movies) AS total_movies FROM franchises GROUP BY original_medium HAVING total_movies &gt; 10
  • Use WHERE clause to filter before grouping
  • Example: SELECT original_medium, SUM(n_movies) AS total_movies FROM franchises WHERE original_medium IN ('movie', 'video game') GROUP BY original_medium

MySQL-Specific Syntax

  • Not all code works in every dialect of SQL.
  • MySQL has its own syntax and features.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

This quiz covers MySQL concepts including filtering data and aggregating data, specifically filtering on numeric columns and performing simple aggregations.

More Like This

MySQL Database Management System
10 questions
Introducción a SQL y MySQL
10 questions
Unit III - SQL & MySQL Notes
33 questions
SQL Basics in MySQL
13 questions

SQL Basics in MySQL

EffortlessDrama avatar
EffortlessDrama
Use Quizgecko on...
Browser
Browser