36
2. Double-clickEqualto.
TheOperatorsboxbecomestheOperandsbox.
3. Double-clickCalculation.
4. TheComplexConditionwizardappears.Thefirstscreenasksyouto
selectacalculationobject.
5. Openthefoldercontainingtheobject,clickontheobject,thenclickBegin.
Thenextscreenasksyoutoselectafunctiontoapplyontheobject.
6. Selectthefunctionfromthelist,thenclickNext.
Thenextscreenasksyoutodefinethelevelofcalculation.
7. Selectalevelofcalculation.
• Toobtainasingleresultrow,clickGlobally,thenclickNext.
• Toobtainseveralresultrows,clickByoneormoreobjects,select
theobjectsfromthelist,thenclickNext.
Thenextscreenasksyoutochoosebetweenmakinganindependent
calculationandcomparingtheresultofthecalculationwiththevaluesof
oneormoreobjects.
8. Selecthowyouwanttosynchronizeyourcalculation.
• Tomakeacalculationindependentlyofyourobjects,click
independentlyofyourobjects,thenclickNext.
• Tomakeacalculationforeachvalueofoneormoreofyourobjects,
whichallowsyoutolimitthecalculationtoparticularobjects,clickFor
eachvalueofoneormoreobjects,selecttheobjetsfromthelist,
thenclickNext.
Thenextscreenasksyoutosetthenumberofvaluestocompare.
9. Selectwhetheryouwanttocomparetheobjectwithatleastonevalue
orwithallvalues.
• Tocomparetheobjectwithatleastonevalue,whichallowsyouto
limitthevaluescomparedwiththeobject,clickAtleastonevalue,
thenclickFinish.
• Tocomparetheobjectwithallvalues,clickAllvalues,thenclick
Finish.
DesktopIntelligenceAccessandAnalysisGuide
191
11
CustomizingQueriesonUniverses
Applyingcomplexconditionsonqueries
33
TheQueryPanelreappearswiththequerydefinedwithaconditionona
calculation.
10. ClickRun.
Example:Todeterminewheneachcustomerlastpaidfora
product
Youwanttofindoutthedateofeachcustomer'slastinvoicesothatyoucan
contactthosecustomerswhohavenotbeenbuyingyourproducts.Toobtain
thisdata,youneedtoapplyacomplexconditionwithacalculation.The
calculationcomparestheinvoicedatesforeachcustomer,thenreturnsonly
thelastdate.
1. InserttheCustomerandInvoiceDateobjectsinaqueryontheIsland
ResortsMarketinguniverse.
2. DragtheInvoiceDateobjecttotheConditionsbox.
3. Double-clicktheEqualtooperator.
4. Double-clicktheCalculationoperand.
TheComplexConditionWizardappears.
5. OpentheSalesclass,clicktheInvoiceDateobject,thenclickBegin.
6. ClickMaximum(youwantthelastinvoicedate),thenclickNext.
7. Inthenextdialogbox,clickGlobally,thenclickNext.
8. Inthenextdialogbox,clickForeachvalueofoneormoreobjects,
thenCustomer.
Thisoptionforcesthecalculationtoreturnthelastinvoicedateper
customer.
9. ClickNext,clickNextagain,then,intheQueryPanel,clickRun.
Oneinvoicedatepercustomerappearsinthereport.
Examiningthecalculationindetail
Let'slookindetailatthecalculationyouhavejustcreatedindetailtomake
whatishappeningclear.
192
DesktopIntelligenceAccessandAnalysisGuide
CustomizingQueriesonUniverses
11
Applyingcomplexconditionsonqueries
32
Whenyouuseacalculation,DesktopIntelligencebuildsSQLthatcontains
asubquery.Asubqueryisaninnerquery.Thedatabasethatreceivesthe
SQLgeneratedbyDesktopIntelligenceevaluatestheresultoftheinner
queryagainsteachrowoftheouterquerytodetermineiftherowshould
appearintheresult.
Notethatyoucancreatesubqueriesexplicitly.SeeApplyingaconditionwith
asubqueryonpage194.
Asyoumovethroughthewizard,youspecify:
• theobjecttouseinthecalculation
Thisistheobjectintheouterquerywhosevalueiscomparedagainstthe
resultoftheinnerquery.Intheexample,theobjectisInvoiceDate.
• theaggregatefunctiontoapplytotheobject
IntheexampleyouappliedtheMaximumfunctionbecauseyouwere
interestedinthemostrecentinvoicedate.
• Thelevelofcalculation.
Thisdeterminesthegroupinginthesubquery.Intheexampleyouchose
Globallybecauseyouwereinterestedsimplyinthecustomer'slatest
invoicedate,notalatestinvoicedatebysomeothercriteria.
• Synchronization.
ThisdeterminesthesubquerylinkstothemainqueryIntheexampleyou
chosetheCustomerobjectbecauseyouwereinterestedineach
customer'slatestinvoicedate.
• Thenumberofvaluestocompare
Thisdetermineshowmanyvaluesinthesubquerythedatabasecompares
againstthevaluesintheouterquery.Intheexampleyoucanchoose
eitheroptionbecausethesubqueryreturnsonerowonlyforeach
customer.
DesktopIntelligenceAccessandAnalysisGuide
193
11
CustomizingQueriesonUniverses
Applyingcomplexconditionsonqueries
41
ExaminingtheSQL
HereistheSQLgeneratedbyDesktopIntelligencefromthecalculationin
theexample:
SELECT
Customer.last_name,
Sales.invoice_date
FROM
Customer,
Sales
WHERE
( Customer.cust_id=Sales.cust_id)
AND (
Sales.invoice_date = = ALL
(
SELECT
max( Sales.invoice_date )
FROM
Sales,
Customer SubAlias__4
WHERE
SubAlias__4.cust_id=Sales.cust_id
AND SubAlias__4.last_name e = Customer.last_name
)
)
• invoice_dateistheobjectusedinthecalculation,sotheSQLjoinsthe
twoqueriesusingtheSales.invoice_datefield.
• Thecalculationlevelisglobal,sothesub-queryhasnogrouping.
• ThequeriesaresynchronizedviatheCustomerobjectsotheSQLcreates
acorrelatedsubqueryonCustomer.last_name.
• Thequerycomparesallthevaluesintheinnerqueryagainsttheouter
query.
Applyingaconditionwithasubquery
Asubqueryisaquerywithinaquery.Itreturnsasinglecolumnofdatawhich
iscomparedwiththedataretrievedbythemainquery.Youusesubqueries
forsituationssuchasfindingasingleindividualinalistofindividualswho
meettheconditionsofthequery.Forexample,ofallcustomerswhomade
194
DesktopIntelligenceAccessandAnalysisGuide
CustomizingQueriesonUniverses
11
Applyingcomplexconditionsonqueries
45
reservations,whatisthenameandaddressofthecustomerwhomadethe
firstreservation?
Complexconditionsonqueriesconsistofthreeelements:anobject,an
operatorandanoperand.ConditionsthatincludetheCreateasubquery
(ALL)operand,ortheCreateasubquery(ANY)operand,generatea
subquery.Theoperator(forexamplegreaterthan,lessthan)thatyouinclude
intheconditiondetermineswhetherthedatareturnedbythesubqueryis,
forexample,excludedfromthemainqueryresult.
Theoperandsthatgenerateasubqueryaredescribedhere.
Andanswersques-
tionssuchas...
Compares...
Thisoperand...
Whichcustomershave
notboughtmylatest
product?
Allthevaluesreturned
bythesubquerywiththe
valuesreturnedbythe
mainquery
Createasubquery
(ALL)
Whichproductsgenerat-
edaboveaveragerev-
enue?
Anyvaluesreturnedby
thesubquerywiththe
valuesreturnedbythe
mainquery
Createasubquery
(ANY)
Toapplyaconditionwithasubquery
1. DraganobjectfromtheClassesandObjectsboxanddropitinthe
ConditionsboxintheQueryPanel.
2. Double-clicktheoperatoryouwanttouse.
Someoperators(forexampleBoth,Between,Matchpattern)cannotbe
usedwithsubqueries.
3. Double-clicktheCreateasubquery(ALL)operandortheCreatea
subquery(ANY)operand.
Atabiscreatedforthesubquery(Subquery1.1).
DesktopIntelligenceAccessandAnalysisGuide
195
11
CustomizingQueriesonUniverses
Applyingcomplexconditionsonqueries
34
4. IntheSubquery1.1tab,insertanobjectintheResultObjectsbox.
Note:Youcanonlyincludeoneresultobjectinthesubquery.
5. Ifnecessary,applyaconditiononthesubquery.
6. ClickRun.
Note:Thesubquery'stabalwaysappearstotherightofthemainquery.A
numberappearsinthetab,(Subqueryn.n).DesktopIntelligenceincrements
thesubquerynumbertoshowtherelationshipbetweenaqueryandits
subqueryorsubqueries.
Example:Whichcustomermadetheearliestreservation?
Youwanttoofferabottleofchampagnetothecustomerwhomadethe
earliestreservation.Toobtainthenameandaddressofthiscustomer:
1. InserttheCustomerobjectandtheAddressobjectinaqueryontheIsland
ResortsMarketinguniverse.
2. DragtheReservationDateobjecttotheConditionsbox.
3. Double-clicktheLessthanorequaltooperator.
4. Double-clicktheCreateasubquery(ALL)operand.
TheSubquery1.1tabnowappearsintheQueryPanel.
5. IntheSubquery1.1tab,inserttheReservationDateobjectintheResult
Objectsbox.
6. ClickRun.
Thenameandaddressofthecustomerwhomadetheearliestreservation
appearsinthereport:
Todeleteasubquery
AsubqueryisgeneratedbyaconditioncontainingtheCreateasubquery
(ALL)operandortheCreateasubquery(ANY)operand.Therefore,you
deleteasubquerybydeletingtheconditioninthemainquery.Todeletethe
condition:
1. RightclicktheconditioniconintheConditionsbox.
2. ClickDeleteontheshortcutmenu.
196
DesktopIntelligenceAccessandAnalysisGuide
CustomizingQueriesonUniverses
11
Applyingcomplexconditionsonqueries
33
Subqueriesandcalculations
TheexampleExample:Todeterminewheneachcustomerlastpaidfora
productonpage192explainsthatcomplexconditionsgeneratesubqueries
behindthescenes.Youcanseethisbyrepeatingtheexampleaboveusing
acomplexconditionwithacalculation.
Example:Todiscoverwhichcustomermadetheearliest
reservation(usingcalculation)
Todiscoverthisusingacomplexconditionwithacalculation:
1. InserttheCustomerandAddressobjectsinaqueryontheIslandResorts
Marketinguniverse.
2. DragtheReservationDateobjecttotheConditionsbox.
3. Double-clicktheEqualtooperator.
4. Double-clicktheCalculationoperand.
TheComplexConditionwizardappears.
5. SelecttheReservationDateobject,thenclickBegin.
6. SelecttheMinimumfunction,thenclickNext.
TheMinimumreturnstheearliest(smallest)reservationdate.
7. SelectGlobally,thenclickNext.
8. SelectIndependentlyofyourobjects,thenclickNext.
Notethatyouareinterestedintheearliestoverallreservationdatesoyou
donotlinkthedatetoanobjectinthemainquery.
9. SelectAllValues,thenclickFinish.
10. Runthequery.
Thequeryreturnsthesameresultasthequerydefinedusingasubqueryto
answerthesamequestion.Examinethesestepsinrelationtothedescription
ofcomplexconditionsintheexampleExample:Todeterminewheneach
customerlastpaidforaproductonpage192ifyouarestillunclearwhythis
isso.
DesktopIntelligenceAccessandAnalysisGuide
197
11
CustomizingQueriesonUniverses
Applyingcomplexconditionsonqueries
34
Usinganexistingqueryinacondition
Youcanusethevaluesreturnedbyanexistingqueryinaconditioninanother
query.Thisissimilarinsomewaystocreatingasubquery.(Youcanexpress
thesamequerieseitherassubqueriesorasqueriesthatusevaluesreturned
byexistingqueries).ThedifferenceisthatDesktopIntelligencedoesnot
buildanSQLstatementcontainingasubquery.Itreturnsthedatafromboth
queries,thenperformsthe'subquery'processingontheclientmachine.
Toreturnlistofresorts/revenueswhereresortcountry
revenue>$1000000
Inthisexampleyouhaveareportcontainingadataproviderthatlistsall
countrieswhoserevenueisgreaterthanorequalto$1,000,000.Youcan
usethisdataprovidertobuildthenewdataproviderthatlistsallresortswithin
thesecountriesandtheresortrevenues.
1. ClickTableontheInsertmenu.
2. Withyourmouse,drawarectanglewhereyouwantthenewblockto
appear.
3. Whenyoureleasethemousebutton,theNewTablewizardappears.
4. ClickBuildanewqueryontheuniversecurrentlyinuse.
TheQueryPanelappears.
5. DragtheResortandRevenueobjectstotheResultObjectswindow.
6. DragtheCountryobjecttotheConditionswindow.
7. Double-clickInlistinthelistofoperators.
Thelistofoperatorschangestoalistofoperands.
8. ClickSelectQueryResultsinthelistofoperands.
Thelistofdataprovidersinthedocumentappears.
9. ExpandthedataproviderandselecttheCountrydimension.
10. ClickOK.
TheconditionappearsintheConditionswindow.
11. ClickRuntorunthequery.
198
DesktopIntelligenceAccessandAnalysisGuide
CustomizingQueriesonUniverses
11
Usinganexistingqueryinacondition
29
Thedataappearsinablockinthereport.
Applyinggroupsofconditions
Youuseconditionstolimitthedataretrievedbyqueries.Agroupofconditions
consistsoftwoormoreconditions(predefined,simpleorcomplex)applied
onthesamequery.
Youusegroupsofconditionswhenasingleconditiondoesnotenableyou
toobtainthedatathatyouneed.
Organizinggroupsofconditions
Agroupofconditionsconsistsoftwoormoreconditionsappliedonthesame
query.IntheConditionsboxintheQueryPanel,conditionsarelinkedbyan
operator(ANDorOR).
Groupsoftwoconditions
Inagroupthatcontainsonlytwoconditions,youdouble-clicktheoperator
tochangeitfromANDtoOR,orviceversa.
Groupsofthreeormoreconditions
Whenyoudouble-clicktheoperatorinagroupthatcontainsatleastthree
conditions,youcreateanindentationinthegroup.
Ingroupsthatcontainthreeormoreconditions,youcanalso:
• Createindentationswithoutreplacingtheoperator,bydraggingthe
operatorhorizontally.
• Moveconditionswithinthegroup.
• Deleteaconditionfromagroup.
Thefollowingtableexplainshowtoorganizegroupsofconditionsindifferent
ways:
DesktopIntelligenceAccessandAnalysisGuide
199
11
CustomizingQueriesonUniverses
Applyinggroupsofconditions
38
Dothis...
To...
Double-clicktheANDorORoperator.
Changeagroup'soperatorfromAND
toORandviceversa
ClicktheANDorORoperatorwith
yourrightmousebutton.
ClickShiftrightorShiftleftonthe
shortcutmenu
Indentoroutdentconditionswithina
groupofconditions
Clicktheconditionandholddown
yourmousebutton.
Dragtheconditiontoanothergroup
ofconditions,thenreleaseyour
mousebutton.
Moveaconditionfromonegroupto
another
ANDandOR
DesktopIntelligenceautomaticallylinksmultipleconditionsusingoperators
intheConditionsboxintheQueryPanel:
• ANDspecifiesaresultthatistrueforbothconditions.
• ORspecifiesaresultthatistrueforeitherthefirstorthesecondcondition.
YoucanreplaceANDwithOR,andviceversa,bydouble-clickingit.When
youapplythreeormoreconditionsonaquery,double-clickingtheoperator
createsanindentationinthegroupofconditions.
Tip:
AvoidgroupsofconditionssuchasYearEqualto2001ANDYearEqualto
2002.Thisexamplewouldreturnnodata,because
Year
cannotbeequalto
twodifferentvalues.Toobtain,forexample,thelistofcustomersfromboth
2001and2002,youwouldhavetobuildacombinedqueryusingthe
200
DesktopIntelligenceAccessandAnalysisGuide
CustomizingQueriesonUniverses
11
Applyinggroupsofconditions
Documents you may be interested
Documents you may be interested