Timedora
Free Online Flashcard Deck

SQL Joins and Aggregation Flashcards Free Online Flashcards

Study SQL Joins and Aggregation with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

Why can joining orders to multiple item rows inflate a revenue sum?

Back

A join returns one row per matching pair. If one order matches several item rows, its order-level amount is repeated and may be overstated when summed.

02
Front

What does conditional aggregation make possible in one grouped query?

Back

Conditional aggregation places conditions inside aggregate expressions, allowing several segment-specific metrics to be calculated in one grouped query.

03
Front

How do `WHERE` and `HAVING` differ in when they filter?

Back

`WHERE` filters individual input rows before grouping; `HAVING` filters completed groups and can test aggregate values.

04
Front

What does `GROUP BY region` define in an order summary?

Back

`GROUP BY region` creates one group per region; aggregate functions such as `COUNT(*)` and `SUM(amount)` calculate values for each group.

05
Front

Where should status exclusions and minimum-revenue requirements go?

Back

Use `WHERE` for a row-level condition such as excluding cancelled orders. Use `HAVING` for group-level requirements such as a minimum order count or revenue.

06
Front

How can you prevent item rows from repeating an order-level amount?

Back

Aggregate each input to the intended grain before joining. For example, summarize items to one row per order before joining that summary to orders.

07
Front

What does an aggregate query without `GROUP BY` summarize?

Back

Without `GROUP BY`, aggregate functions treat the input as one group and produce an overall summary.

08
Front

How can a grouped query sum amounts only for paid orders?

Back

Use `SUM(CASE WHEN status = 'paid' THEN amount ELSE 0 END)` to sum paid-order amounts within each group.

09
Front

Do multiple joined rows per order prove the source contains duplicates?

Back

A join that produces multiple rows per entity does not by itself prove the source has duplicate records; the entity may legitimately match several related rows.

10
Front

How should a selected non-aggregated column relate to `GROUP BY`?

Back

Every selected column outside an aggregate should identify the group, usually by appearing in `GROUP BY`; otherwise, a group may contain several possible values for it.

11
Front

Which clause retains only regions with at least 100 orders?

Back

Use `HAVING`, because the condition tests an aggregate value calculated for each completed group.

12
Front

Why use `ELSE 0` in a conditional `SUM`?

Back

Use `ELSE 0` when a nonmatching row should contribute zero to the sum. Without `ELSE`, a false `CASE` condition returns `NULL`, which `SUM` ignores.