SELECT DISTINCT FROM <model > (DMX)
Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).
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.
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.
The unique values in the column.
The midpoint for each discretized bucket in the column.
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, Gender.
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]
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.
You can also change the mining model created in the Basic Mining Tutorial to discretize the mining structure column, [Yearly Income]. For information about how to do this, see Change the Discretization of a Column in a Mining Model. However, when you change the discretization of the column, it will force the mining structure to be reprocessed, which will change the results of other models that you have built using that structure.
SELECT DISTINCT [Yearly Income] AS [Bucket Average], RangeMin([Yearly Income]) AS [Bucket Minimum], RangeMax([Yearly Income]) AS [Bucket Maximum] FROM [TM Decision Tree]
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
The minimum value of the minimum bucket and the maximum value of the maximum bucket are just the highest and lowest observed values. Any values that fall outside this observed range are assumed to belong to the minimum and maximum buckets.