25 combined queries - · pdf filecombined queries 411 25 combined queries ... web...

5
Combined Queries 411 25 Combined Queries Combined Queries are multiple queries on the same universe but return a single data set, i.e. multiple queries are defined and run but only one set of values is returned. Combined Queries could be used to answer questions such as: 1. Get a list of Customer Codes who purchased items in June this year and/or Customer Codes who purchased items in June last year. This would be done using a Union query and the results would include a single occurrence of each Customer Code (even if they purchased items in both years). 2. Get a list of Customer Codes who purchased items in June of this year and also June of last year. This would be done using an Intersection query and would include only those Customer Codes that had purchased items in June this year and also June last year. 3. Get a list of Customer Codes who purchased items in June last year and did not purchase items in June this year. This would be done using a Minus query. NOTE – In each of the above scenarios, 2 queries are run and the results are then ‘merged’ in different ways to produce a single data set. 25.1 Types of Combined Queries There are three types of Combined Queries: Union Web Intelligence (or the database) combines all the data from both queries, eliminates duplicate rows, and returns the unique rows only. Intersection Web Intelligence (or the database) returns the data that is common to both queries. Minus Web Intelligence (or the database) returns the data in the first query that does not appear in the second.

Upload: vothuy

Post on 13-Feb-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 25 Combined Queries -  · PDF fileCombined Queries 411 25 Combined Queries ... Web Intelligence adds a copy of the initial query to the data provider. The second query has the

Combined Queries

411

25 Combined Queries

Combined Queries are multiple queries on the same universe but return a single data set, i.e. multiple queries are defined and run but only one set of values is returned. Combined Queries could be used to answer questions such as:

1. Get a list of Customer Codes who purchased items in June this year and/or Customer Codes who purchased items in June last year.

This would be done using a Union query and the results would include a single occurrence of each Customer Code (even if they purchased items in both years).

2. Get a list of Customer Codes who purchased items in June of this year and also June of last

year.

This would be done using an Intersection query and would include only those Customer Codes that had purchased items in June this year and also June last year.

3. Get a list of Customer Codes who purchased items in June last year and did not purchase

items in June this year.

This would be done using a Minus query.

NOTE – In each of the above scenarios, 2 queries are run and the results are then ‘merged’ in different ways to produce a single data set.

25.1 Types of Combined Queries

There are three types of Combined Queries:

Union Web Intelligence (or the database) combines all the data from both queries, eliminates duplicate rows, and returns the unique rows only.

Intersection Web Intelligence (or the database) returns the data that is common to both queries.

Minus Web Intelligence (or the database) returns the data in the first query that does not appear in the second.

Page 2: 25 Combined Queries -  · PDF fileCombined Queries 411 25 Combined Queries ... Web Intelligence adds a copy of the initial query to the data provider. The second query has the

Combined Queries

412

Examples: We have two queries with independent results as shown below:

Query Results

Query 1

California New York Texas

Query 2 California Florida

Depending on the type of combined query, Web Intelligence returns the following values:

Combined Query Type

Combined Query Results

Union

California Florida New York Texas

Intersection

California

Minus

New York Texas

25.2 How does Web Intelligence generate Combined Queries?

If your database supports the type of combination specified in your query then Web Intelligence generates the relevant SQL for the database. If your database does not support the type of combination in your query then Web Intelligence performs the Combination Query within the report, i.e. by generating multiple SQL queries and then resolving the data after retrieval from the database.

25.3 What can you do with Combined Queries?

Combined Queries allow you to answer questions that are otherwise difficult or impossible to frame in a single Web Intelligence query. Example (using eFashion):

We want to prepare for the next Christmas period and have been given the requirement:

Produce a list of categories sold in Christmas period last year but not sold in Christmas period of this year.

Using Combined Queries we can obtain the results by using the MINUS operator (shown next in ‘Building a Combined Query’).

Page 3: 25 Combined Queries -  · PDF fileCombined Queries 411 25 Combined Queries ... Web Intelligence adds a copy of the initial query to the data provider. The second query has the

Combined Queries

413

25.4 Building a Combined Query

You build a combined query in the Query Panel. 1. Create the following query using the ‘eFashion’ universe.

NOTE

We have found from evaluating results of queries that Oracle does not require this to be unchecked, but Microsoft Access does require it to be ticked. If you are unsure whether your database supports Combined Queries then always uncheck this property.

2. If required, uncheck the query property ‘Retrieve duplicate rows’ (see NOTE above).

3. Click ‘Add a combined query’ on the toolbar.

Web Intelligence adds a copy of the initial query to the data provider. The second query has the following characteristics:

It contains the same Result Objects as the original query.

It does not contain the filters defined on the original query.

By default, it is combined with the original query in a UNION relationship.

The individual queries in the combined queries will be named Combined Query 1, Combined Query 2, Combined Query n, etc.

Page 4: 25 Combined Queries -  · PDF fileCombined Queries 411 25 Combined Queries ... Web Intelligence adds a copy of the initial query to the data provider. The second query has the

Combined Queries

414

4. Build up Query Filters for the second query.

5. For our example we need to use a Minus query so:

6. Run the query and you will be prompted to select a Query Context:

Query Contexts were described in an earlier session using the Island Resort Marketing universe. In this example, select ‘Shop facts’ as shown opposite. The reason we are being asked to select a Query Context is because our query contains objects from the Product and Time period classes but no measure objects. Product is independent of Time, but they are related via an activity of some sort, e.g. Shop facts or Promotions. Please revisit session on Query Contexts for more info.

NOTE – You will have to select ‘Shop facts’ twice as we have 2 Combined Queries and they are both affected by context selection.

Click on Union to change to Intersect and

then click again to change to Minus.

Page 5: 25 Combined Queries -  · PDF fileCombined Queries 411 25 Combined Queries ... Web Intelligence adds a copy of the initial query to the data provider. The second query has the

Combined Queries

415

25.5 Combined Query Structure

The queries within a Combined Query must return the same number of objects, each object must be of the same data type, and the objects must be in the same order. You cannot combine queries when the number of objects in the query and the data types of those objects are not identical.

For example:

You cannot combine a query that returns [Year] with a query that returns [Year] and [Sales revenue].

You cannot combine a query that returns [State] with a query that returns [Revenue].

1. It is possible to combine a query that returns [State] with a query that returns [Category] if both

dimensions are of the same data type. The result will be a mixed list of states and categories – this query is unlikely to be meaningful.

2. Typically, if your first Combined Query contains a particular dimension or detail object (e.g.

[Year]), then your second Combined Query should also contain a dimension or detail object that returns a list of similar values.

3. Objects do not have to have the same name in Combined Queries, but they should be in the

same order within their respective queries and return similar values, unless a mixed list is required (see point 1 above).

The results shows 4 categories were sold in the Christmas period of last year but not in the Christmas period of this year. These results could now be used for further analysis to prepare for next year’s Christmas period. NOTE – If you do not get the results shown opposite then edit the query and make sure you have unticked the property: