\begin{frame}
\frametitle{Group By}
\begin{goal}{}
``Group by'' \emph{partitions} the rows of
a table into \emph{disjoint groups}:
\begin{itemize}
\item based on \emph{value equality for the \sql{group by} attributes}.
\end{itemize}
Aggregation functions applied for each group separately.
\end{goal}
\pause
\medskip
\begin{code}{\textwidth}{Average points for \underline{each} homework}
\footnotesize
\parbox{0.4\textwidth}{%
\BUseVerbatim{query}
}
\hfill
\parbox{0.5\textwidth}{%
\footnotesize\centering\ttfamily
\colorbox{rellight}{%
\begin{tabular}{|r|r|}
\hline
\hd{number} & \hd{avg(points)}
\\
\hline
1 & 8 \\
2 & 8.5 \\
\hline
\end{tabular}%
}
}
\end{code}
All tuples agreeing in their \sql{number} values for a group:
\begin{tcenter}
\footnotesize\ttfamily
\colorbox{rellight}{%
\begin{tabular}{|r|r|r|r|}
\hline
\hd{sid} & \hd{category} & \hd{number} & \hd{points}
\\
\hline
101 & homework & 1 & 10 \\
102 & homework & 1 & 9 \\
103 & homework & 1 & 5 \\
\hline\hline
101 & homework & 2 & 8 \\
101 & homework & 2 & 9 \\
\hline
\end{tabular}%
}
\end{tcenter}
\end{frame}