SELECT DISTINCT FROM <model > (DMX)
Updated: March 2, 2016
Returns all possible states for the selected column in the model. The values that are returned vary depending on whether the specified column contains discrete values, discretized numeric values, or continuous numeric values.
SELECT [FLATTENED] DISTINCT [TOP <n>] <expression list> FROM <model> [WHERE <condition list>][ORDER BY <expression>]
Optional. An integer specifying how many rows to return.
A comma-separated list of related column identifiers (derived from the model) or expressions.
A model identifier.
A condition to restrict the values that are returned from the column list.
Optional. An expression that returns a scalar value.
The SELECT DISTINCT FROM statement only works with a single column or with a set of related columns. This clause does not work with a set of unrelated columns.
The SELECT DISTINCT FROM statement allows you to directly reference a column inside of a nested table. For example:
<model>.<table column reference>.<column reference>
The results of the SELECT DISTINCT FROM <model> statement vary, depending on the column type. The following table describes the supported column types and the output from the statement.
|Discrete||The unique values in the column.|
|Discretized||The midpoint for each discretized bucket in the column.|
|Continuous||The midpoint for the values in the column.|
The following code sample is based on the
[TM Decision Tree] model that you create in the Basic Data Mining Tutorial. The query returns the unique values that exist in the discrete column,
SELECT DISTINCT [Gender] FROM [TM Decision Tree]
For columns that contain discrete values, the results always include the Missing state, shown as a null value.
The following code sample returns the midpoint, minimum age, and maximum age for all of the values in the column.
SELECT DISTINCT [Age] AS [Midpoint Age], RangeMin([Age]) AS [Minimum Age], RangeMax([Age]) AS [Maximum Age] FROM [TM Decision Tree]
|Midpoint Age||Minimum Age||Maximum Age|
The query also returns a single row of null values, to represent missing values.
The following code sample returns the midpoint, maximum, and minimum values for each bucket that has been created by the algorithm for the column, [
Yearly Income]. To reproduce the results for this example, you must create a new mining structure that is the same as
[Targeted Mailing]. In the wizard, change the content type of the
Yearly Income column from Continuous to Discretized.
SELECT DISTINCT [Yearly Income] AS [Bucket Average], RangeMin([Yearly Income]) AS [Bucket Minimum], RangeMax([Yearly Income]) AS [Bucket Maximum] FROM [TM Decision Tree]
|Bucket Average||Bucket Minimum||Bucket Maximum|
You can see that the values of the [Yearly Income] column have been discretized into five buckets, plus an additional row of null values, to represent missing values.
The number of decimal places in the results depends on the client that you use for querying. Here they have been rounded to two decimal places, both for simplicity and to reflect the values that are displayed in SQL Server Data Tools (SSDT).
For example, if you browse the model by using the Decision Tree viewer and click a node that contains customers grouped by income, the following node properties are displayed in the Tooltip:
Age >=69 AND Yearly Income < 39221.41