Database Reference
In-Depth Information
Figure 6.31
Use PIVOT.
he code in Figure 6.31 uses the built-in function COUNT to count the number of elements
in each category. Details about built-in functions will be given later in this chapter. he word
MyResult at the end of the SQL statement is the name of the pivot table, which can be used for
other data analysis tasks.
At this point, you have learned most of the commonly used operators through examples. For
querying tasks that involve more than one table, subqueries or the JOIN keyword can be used. In
the next section, you will learn how to use subqueries.
6.3 Subqueries
he search condition in a WHERE clause may depend on the result returned by a subquery.
he result set returned by a subquery will be used as the search condition in the main query. he
output returned by a subquery may include one or more values. If the output has only a single
value, the = operator is used to match the comparison value in the WHERE clause. If the output
returned by a subquery contains more than one value, the IN or EXIST operator should be used to
handle the multiple valued output. he example in Figure 6.32 selects database classes. Since the
class and course information are from two diferent tables, a subquery is used to retrieve the course
Figure 6.32
Use subquery that returns single value.
Search WWH ::




Custom Search