Chapter 14: Spelunking—Exploration Using Data Mining 547
WHERE Clause
The WHERE clause enables us to fi lter the result of the SELECT statement. The
fi lter conditions in the WHERE clause are applied after the predictions are made by
the mining model. Therefore, we can use the prediction result as part of the fi lter.
For example, if the Neural Network - Children At Home mining model is predicting
Num Children At Home, we can create a fi lter to give us only those records where
Num Children At Home was predicted to be 0:
WHERE [Neural Network – Children At Home].[Num Children At Home] = 0
ORDER BY Clause
The ORDER BY clause lets us sort the result set: we can sort in either ascending or
descending order. Adding DESC to the clause provides a descending sort. Adding
ASC to the clause provides an ascending sort. ASC is the default sort order when
neither ASC nor DESC is specifi ed.
The ORDER BY clause in T-SQL includes a comma-separated list of fi elds
to provide the sort columns. The ORDER BY clause in DMX is a bit different. It
allows only a single expression. If we want to sort by more than one column, we
need to create an expression concatenating these two columns, as follows:
ORDER BY [Lname] + [Fname] ASC
Types of Prediction Queries
Several types of prediction queries are available to us. As stated earlier, the format or
absence of the PREDICTION JOIN clause determines the type of prediction query
being created. Let’s look at the format and operation of each type.
PREDICTION JOIN
The standard prediction join query enables us to take records from another data
source and feed those results into our mining model to create predictions. For this
to happen, we must specify where the joined data is coming from. We also need to
specify how the columns in the data source are mapped to the input columns of the
mining model.
A typical PREDICTION JOIN clause looks like this:
PREDICTION JOIN
OPENQUERY([Max Min Sales DM],
'SELECT
[Fname],
[Lname],