SlideShare ist ein Scribd-Unternehmen logo
1 von 14
www.regoconsulting.com Phone: 1-888-813-0444
Creating and Tuning SQL Queries that Engage Users
Writing Efficient
SQL, CA PPM
(CA Clarity PPM)
www.regoconsulting.com Phone: 1-888-813-0444
2
● Develop queries that perform well
● Develop queries that scale well
● Develop queries that are concise and easy to debug
● Develop queries that use the data model efficiently
Goal
www.regoconsulting.com Phone: 1-888-813-0444
3
● Using table aliases
● Eliminate unnecessary joins
● Sub-queries
● Starting with most restrictive criteria
● IN vs EXISTS
● DISTICT vs EXISTS
● OBS Filtering
● UNION queries
● Inline views
General tips
www.regoconsulting.com Phone: 1-888-813-0444
4
● Improves readability of sql
● Use meaningful table aliases
SELECT A.ID
FROM SRM_RESOURCES A
JOIN ODF_CA_RESOURCE B ON A.ID = B.ID
● Allows queries to be modified more easily
SELECT ID
FROM SRM_RESOURCES
JOIN ODF_CA_RESOURCE ON SRM_RESOURCES.ID = ODF_CA_RESOURCE.ID
● Help performance by eliminating the need for the database to
search the tables for the referenced column
Table Aliases
www.regoconsulting.com Phone: 1-888-813-0444
5
● Remove unnecessary tables from queries
● Avoid falling back on common tables
○ INV_INVESTMENTS
○ SRM_RESOURCES
● Query to find role allocation hours on a project
SELECT SUM(TM.PRALLOCSUM / 3600) HOURS
FROM INV_INVESTMENTS INVI
JOIN PRTEAM TM ON INVI.ID = TM.PRPROJECTID
JOIN SRM_RESOURCES SRMR ON TM.PRRESOURCEID = SRMR.ID
JOIN PRJ_RESOURCES PRJR ON SRMR.ID = PRJR.PRID
WHERE INVI.ID = 50000001 AND PRJR.PRISROLE = 1
Unnecessary joins
www.regoconsulting.com Phone: 1-888-813-0444
6
● Sub-queries can be handy
● How many projects is a resource assigned to
SELECT SRMR.FULL_NAME
, (SELECT COUNT(*) FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) TEAM_COUNT
FROM SRM_RESOURCES SRMR
ORDER BY SRMR.FULL_NAME
● Instead of a LEFT JOIN to a large inline view
SELECT SRMR.FULL_NAME, TM.TEAM_COUNT
FROM SRM_RESOURCES SRMR
LEFT JOIN (SELECT TM.PRRESOURCEID, COUNT(*) TEAM_COUNT
FROM PRTEAM TM
GROUP BY TM.PRRESOURCEID) TM ON SRMR.ID = TM.PRRESOURCEID
ORDER BY SRMR.FULL_NAME
● Avoid substituting sub-queries for table joins
SELECT SRMR.FULL_NAME
, (SELECT COUNT(*) FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) TEAM_COUNT
, (SELECT SUM(TM.PRALLOCSUM) / 3600 FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) TOTAL_ALLOC
, (SELECT SUM(TM.HARD_SUM) / 3600 FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) TOTAL_HALLOC
FROM SRM_RESOURCES SRMR
ORDER BY SRMR.FULL_NAME
Sub-queries
www.regoconsulting.com Phone: 1-888-813-0444
7
● Begin queries with the most restrictive conditions
SELECT SRMR.FULL_NAME, AV.SLICE_DATE, AV.SLICE
FROM SRM_RESOURCES SRMR
JOIN PRJ_BLB_SLICES AV ON SRMR.ID = AV.PRJ_OBJECT_ID AND AV.SLICE_REQUEST_ID = 7
WHERE SRMR.ID = 1
ORDER BY SRMR.FULL_NAME, AV.SLICE_DATE
● Instead of
SELECT SRMR.FULL_NAME, AV.SLICE_DATE, AV.SLICE
FROM PRJ_BLB_SLICES AV
JOIN SRM_RESOURCES SRMR ON AV.PRJ_OBJECT_ID = SRMR.ID
WHERE AV.SLICE_REQUEST_ID = 7
AND SRMR.ID = 1
ORDER BY SRMR.FULL_NAME, AV.SLICE_DATE
Restrictive conditions
www.regoconsulting.com Phone: 1-888-813-0444
8
● IN is typically better when the inner query contains a small
result set
SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE SRMR.ID IN (SELECT TM.PRRESOURCEID FROM PRTEAM TM WHERE TM.PRPROJECTID IN (5000000, 5000001))
SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE EXISTS (SELECT 1 FROM PRTEAM TM WHERE TM.PRPROJECTID IN (5000000, 5000001) AND TM.PRRESOURCEID =
SRMR.ID)
● EXISTS is typically better when the inner query contains a
large result set
SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE SRMR.ID IN (SELECT TM.PRRESOURCEID FROM PRTEAM TM)
SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE EXISTS (SELECT 1 FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID)
IN vs. EXISTS
www.regoconsulting.com Phone: 1-888-813-0444
9
● Both methods are commonly used to derive unique values for
dimension keys of portlets
● EXISTS is preferable to DISTINCT
● DISTINCT produces the entire result set (including duplicates),
sorts, and then filters out duplicates
SELECT DISTINCT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
JOIN PRTEAM TM ON SRMR.ID = TM.PRRESOURCEID
● EXISTS proceeds with fetching rows immediately after the
sub-query condition has been satisfied the first time
SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE EXISTS (SELECT 1 FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID)
DISTINCT vs. EXISTS
www.regoconsulting.com Phone: 1-888-813-0444
10
● Seen many ways to filter based on OBS
● Many rely on complex logic, left joins to inline views, or
multiple sub-queries
● Using EXISTS and the OBS_UNITS_FLAT_BY_MODE table
provides an easy solution
● Filter by Unit Only, Unit and Descendants, or Units and
Ancestors
SELECT SRMR.FULL_NAME
FROM SRM_RESOURCES SRMR
WHERE (:OBS_ID IS NULL OR
EXISTS (SELECT 1
FROM OBS_UNITS_FLAT_BY_MODE OBSM
JOIN PRJ_OBS_ASSOCIATIONS OBSA ON OBSM.LINKED_UNIT_ID = OBSA.UNIT_ID AND OBSA.TABLE_NAME = 'SRM_RESOURCES'
WHERE OBSM.UNIT_ID = :OBS_ID
AND OBSM.UNIT_MODE = NVL(:OBS_MODE, 'OBS_UNIT_AND_CHILDREN')
AND OBSA.RECORD_ID = SRMR.ID))
OBS Filtering
www.regoconsulting.com Phone: 1-888-813-0444
11
● UNION queries perform poorly as they scan through the same data multiple
times
● Require any logic changes to be made in multiple locations
SELECT CODE, NAME, SUM(FORECAST_COST) FORECAST_COST, SUM(BUDGET_COST) BUDGET_COST
FROM (SELECT INVI.CODE, INVI.NAME, FP.TOTAL_COST FORECAST_COST, 0 BUDGET_COST
FROM INV_INVESTMENTS INVI
JOIN FIN_PLANS FP ON INVI.ID = FP.OBJECT_ID AND INVI.ODF_OBJECT_CODE = FP.OBJECT_CODE
WHERE FP.IS_PLAN_OF_RECORD = 1 AND FP.PLAN_TYPE_CODE = 'FORECAST'
UNION ALL
SELECT INVI.CODE, INVI.NAME, 0 FORECAST_COST, FP.TOTAL_COST BUDGET_COST
FROM INV_INVESTMENTS INVI
JOIN FIN_PLANS FP ON INVI.ID = FP.OBJECT_ID AND INVI.ODF_OBJECT_CODE = FP.OBJECT_CODE
WHERE FP.IS_PLAN_OF_RECORD = 1 AND FP.PLAN_TYPE_CODE = 'BUDGET')
WHERE INVI.CODE = 'PROJ01763'
GROUP BY CODE, NAM
● Most UNION queries can easily be replaced with logic
SELECT INVI.CODE, INVI.NAME
, SUM(CASE WHEN FP.PLAN_TYPE_CODE = 'FORECAST' THEN FP.TOTAL_COST END) FORECAST_COST
, SUM(CASE WHEN FP.PLAN_TYPE_CODE = 'BUDGET' THEN FP.TOTAL_COST END) BUDGET_COST
FROM INV_INVESTMENTS INVI
JOIN FIN_PLANS FP ON INVI.ID = FP.OBJECT_ID AND INVI.ODF_OBJECT_CODE = FP.OBJECT_CODE
WHERE FP.IS_PLAN_OF_RECORD = 1 AND INVI.CODE = 'PROJ01763'
GROUP BY INVI.CODE, INVI.NAME
● Only use UNION when joining data from multiple tables
UNION queries
www.regoconsulting.com Phone: 1-888-813-0444
12
● Inline views can be very beneficial but can severely affect
performance
● LEFT JOINs to large inline views is typically not a good idea
SELECT SRMR.FULL_NAME, SUM(AV.SLICE) AVAIL, AL.ALLOC
FROM SRM_RESOURCES SRMR
JOIN PRJ_BLB_SLICES AV ON SRMR.ID = AV.PRJ_OBJECT_ID AND AV.SLICE_REQUEST_ID = 7
LEFT JOIN (SELECT TM.PRRESOURCEID, SUM(AL.SLICE) ALLOC
FROM PRTEAM TM
JOIN PRJ_BLB_SLICES AL ON TM.PRID = AL.PRJ_OBJECT_ID
WHERE AL.SLICE_REQUEST_ID = 6
AND AL.SLICE_DATE BETWEEN '01-JAN-14' AND '30-JUN-14'
GROUP BY TM.PRRESOURCEID) AL ON SRMR.ID = AL.PRRESOURCEID
WHERE AV.SLICE_DATE BETWEEN '01-JAN-14' AND '30-JUN-14'
GROUP BY SRMR.FULL_NAME, AL.ALLOC
ORDER BY SRMR.FULL_NAME
● Will work through some examples to demonstrate
alternatives
Inline views
www.regoconsulting.com Phone: 1-888-813-0444
13
● Resource ETC and Actuals by month
● Eliminating large LEFT JOINs
● Eliminating an unnecessary join
● Using EXISTS
● Summarizing data
● Running totals
● Selecting latest status report
● Concatenating multi-valued lookup values into a string
Interactive Examples
www.regoconsulting.com Phone: 1-888-813-0444
14
Thank you.
Questions
Contact US
888.813.0444
Email Contact
info@regoconsulting.com
Web Site
www.regoconsulting.com

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Kürzlich hochgeladen (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Rego University: Writing SQL Queries, CA PPM (CA Clarity PPM)

  • 1. www.regoconsulting.com Phone: 1-888-813-0444 Creating and Tuning SQL Queries that Engage Users Writing Efficient SQL, CA PPM (CA Clarity PPM)
  • 2. www.regoconsulting.com Phone: 1-888-813-0444 2 ● Develop queries that perform well ● Develop queries that scale well ● Develop queries that are concise and easy to debug ● Develop queries that use the data model efficiently Goal
  • 3. www.regoconsulting.com Phone: 1-888-813-0444 3 ● Using table aliases ● Eliminate unnecessary joins ● Sub-queries ● Starting with most restrictive criteria ● IN vs EXISTS ● DISTICT vs EXISTS ● OBS Filtering ● UNION queries ● Inline views General tips
  • 4. www.regoconsulting.com Phone: 1-888-813-0444 4 ● Improves readability of sql ● Use meaningful table aliases SELECT A.ID FROM SRM_RESOURCES A JOIN ODF_CA_RESOURCE B ON A.ID = B.ID ● Allows queries to be modified more easily SELECT ID FROM SRM_RESOURCES JOIN ODF_CA_RESOURCE ON SRM_RESOURCES.ID = ODF_CA_RESOURCE.ID ● Help performance by eliminating the need for the database to search the tables for the referenced column Table Aliases
  • 5. www.regoconsulting.com Phone: 1-888-813-0444 5 ● Remove unnecessary tables from queries ● Avoid falling back on common tables ○ INV_INVESTMENTS ○ SRM_RESOURCES ● Query to find role allocation hours on a project SELECT SUM(TM.PRALLOCSUM / 3600) HOURS FROM INV_INVESTMENTS INVI JOIN PRTEAM TM ON INVI.ID = TM.PRPROJECTID JOIN SRM_RESOURCES SRMR ON TM.PRRESOURCEID = SRMR.ID JOIN PRJ_RESOURCES PRJR ON SRMR.ID = PRJR.PRID WHERE INVI.ID = 50000001 AND PRJR.PRISROLE = 1 Unnecessary joins
  • 6. www.regoconsulting.com Phone: 1-888-813-0444 6 ● Sub-queries can be handy ● How many projects is a resource assigned to SELECT SRMR.FULL_NAME , (SELECT COUNT(*) FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) TEAM_COUNT FROM SRM_RESOURCES SRMR ORDER BY SRMR.FULL_NAME ● Instead of a LEFT JOIN to a large inline view SELECT SRMR.FULL_NAME, TM.TEAM_COUNT FROM SRM_RESOURCES SRMR LEFT JOIN (SELECT TM.PRRESOURCEID, COUNT(*) TEAM_COUNT FROM PRTEAM TM GROUP BY TM.PRRESOURCEID) TM ON SRMR.ID = TM.PRRESOURCEID ORDER BY SRMR.FULL_NAME ● Avoid substituting sub-queries for table joins SELECT SRMR.FULL_NAME , (SELECT COUNT(*) FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) TEAM_COUNT , (SELECT SUM(TM.PRALLOCSUM) / 3600 FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) TOTAL_ALLOC , (SELECT SUM(TM.HARD_SUM) / 3600 FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) TOTAL_HALLOC FROM SRM_RESOURCES SRMR ORDER BY SRMR.FULL_NAME Sub-queries
  • 7. www.regoconsulting.com Phone: 1-888-813-0444 7 ● Begin queries with the most restrictive conditions SELECT SRMR.FULL_NAME, AV.SLICE_DATE, AV.SLICE FROM SRM_RESOURCES SRMR JOIN PRJ_BLB_SLICES AV ON SRMR.ID = AV.PRJ_OBJECT_ID AND AV.SLICE_REQUEST_ID = 7 WHERE SRMR.ID = 1 ORDER BY SRMR.FULL_NAME, AV.SLICE_DATE ● Instead of SELECT SRMR.FULL_NAME, AV.SLICE_DATE, AV.SLICE FROM PRJ_BLB_SLICES AV JOIN SRM_RESOURCES SRMR ON AV.PRJ_OBJECT_ID = SRMR.ID WHERE AV.SLICE_REQUEST_ID = 7 AND SRMR.ID = 1 ORDER BY SRMR.FULL_NAME, AV.SLICE_DATE Restrictive conditions
  • 8. www.regoconsulting.com Phone: 1-888-813-0444 8 ● IN is typically better when the inner query contains a small result set SELECT SRMR.FULL_NAME FROM SRM_RESOURCES SRMR WHERE SRMR.ID IN (SELECT TM.PRRESOURCEID FROM PRTEAM TM WHERE TM.PRPROJECTID IN (5000000, 5000001)) SELECT SRMR.FULL_NAME FROM SRM_RESOURCES SRMR WHERE EXISTS (SELECT 1 FROM PRTEAM TM WHERE TM.PRPROJECTID IN (5000000, 5000001) AND TM.PRRESOURCEID = SRMR.ID) ● EXISTS is typically better when the inner query contains a large result set SELECT SRMR.FULL_NAME FROM SRM_RESOURCES SRMR WHERE SRMR.ID IN (SELECT TM.PRRESOURCEID FROM PRTEAM TM) SELECT SRMR.FULL_NAME FROM SRM_RESOURCES SRMR WHERE EXISTS (SELECT 1 FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) IN vs. EXISTS
  • 9. www.regoconsulting.com Phone: 1-888-813-0444 9 ● Both methods are commonly used to derive unique values for dimension keys of portlets ● EXISTS is preferable to DISTINCT ● DISTINCT produces the entire result set (including duplicates), sorts, and then filters out duplicates SELECT DISTINCT SRMR.FULL_NAME FROM SRM_RESOURCES SRMR JOIN PRTEAM TM ON SRMR.ID = TM.PRRESOURCEID ● EXISTS proceeds with fetching rows immediately after the sub-query condition has been satisfied the first time SELECT SRMR.FULL_NAME FROM SRM_RESOURCES SRMR WHERE EXISTS (SELECT 1 FROM PRTEAM TM WHERE TM.PRRESOURCEID = SRMR.ID) DISTINCT vs. EXISTS
  • 10. www.regoconsulting.com Phone: 1-888-813-0444 10 ● Seen many ways to filter based on OBS ● Many rely on complex logic, left joins to inline views, or multiple sub-queries ● Using EXISTS and the OBS_UNITS_FLAT_BY_MODE table provides an easy solution ● Filter by Unit Only, Unit and Descendants, or Units and Ancestors SELECT SRMR.FULL_NAME FROM SRM_RESOURCES SRMR WHERE (:OBS_ID IS NULL OR EXISTS (SELECT 1 FROM OBS_UNITS_FLAT_BY_MODE OBSM JOIN PRJ_OBS_ASSOCIATIONS OBSA ON OBSM.LINKED_UNIT_ID = OBSA.UNIT_ID AND OBSA.TABLE_NAME = 'SRM_RESOURCES' WHERE OBSM.UNIT_ID = :OBS_ID AND OBSM.UNIT_MODE = NVL(:OBS_MODE, 'OBS_UNIT_AND_CHILDREN') AND OBSA.RECORD_ID = SRMR.ID)) OBS Filtering
  • 11. www.regoconsulting.com Phone: 1-888-813-0444 11 ● UNION queries perform poorly as they scan through the same data multiple times ● Require any logic changes to be made in multiple locations SELECT CODE, NAME, SUM(FORECAST_COST) FORECAST_COST, SUM(BUDGET_COST) BUDGET_COST FROM (SELECT INVI.CODE, INVI.NAME, FP.TOTAL_COST FORECAST_COST, 0 BUDGET_COST FROM INV_INVESTMENTS INVI JOIN FIN_PLANS FP ON INVI.ID = FP.OBJECT_ID AND INVI.ODF_OBJECT_CODE = FP.OBJECT_CODE WHERE FP.IS_PLAN_OF_RECORD = 1 AND FP.PLAN_TYPE_CODE = 'FORECAST' UNION ALL SELECT INVI.CODE, INVI.NAME, 0 FORECAST_COST, FP.TOTAL_COST BUDGET_COST FROM INV_INVESTMENTS INVI JOIN FIN_PLANS FP ON INVI.ID = FP.OBJECT_ID AND INVI.ODF_OBJECT_CODE = FP.OBJECT_CODE WHERE FP.IS_PLAN_OF_RECORD = 1 AND FP.PLAN_TYPE_CODE = 'BUDGET') WHERE INVI.CODE = 'PROJ01763' GROUP BY CODE, NAM ● Most UNION queries can easily be replaced with logic SELECT INVI.CODE, INVI.NAME , SUM(CASE WHEN FP.PLAN_TYPE_CODE = 'FORECAST' THEN FP.TOTAL_COST END) FORECAST_COST , SUM(CASE WHEN FP.PLAN_TYPE_CODE = 'BUDGET' THEN FP.TOTAL_COST END) BUDGET_COST FROM INV_INVESTMENTS INVI JOIN FIN_PLANS FP ON INVI.ID = FP.OBJECT_ID AND INVI.ODF_OBJECT_CODE = FP.OBJECT_CODE WHERE FP.IS_PLAN_OF_RECORD = 1 AND INVI.CODE = 'PROJ01763' GROUP BY INVI.CODE, INVI.NAME ● Only use UNION when joining data from multiple tables UNION queries
  • 12. www.regoconsulting.com Phone: 1-888-813-0444 12 ● Inline views can be very beneficial but can severely affect performance ● LEFT JOINs to large inline views is typically not a good idea SELECT SRMR.FULL_NAME, SUM(AV.SLICE) AVAIL, AL.ALLOC FROM SRM_RESOURCES SRMR JOIN PRJ_BLB_SLICES AV ON SRMR.ID = AV.PRJ_OBJECT_ID AND AV.SLICE_REQUEST_ID = 7 LEFT JOIN (SELECT TM.PRRESOURCEID, SUM(AL.SLICE) ALLOC FROM PRTEAM TM JOIN PRJ_BLB_SLICES AL ON TM.PRID = AL.PRJ_OBJECT_ID WHERE AL.SLICE_REQUEST_ID = 6 AND AL.SLICE_DATE BETWEEN '01-JAN-14' AND '30-JUN-14' GROUP BY TM.PRRESOURCEID) AL ON SRMR.ID = AL.PRRESOURCEID WHERE AV.SLICE_DATE BETWEEN '01-JAN-14' AND '30-JUN-14' GROUP BY SRMR.FULL_NAME, AL.ALLOC ORDER BY SRMR.FULL_NAME ● Will work through some examples to demonstrate alternatives Inline views
  • 13. www.regoconsulting.com Phone: 1-888-813-0444 13 ● Resource ETC and Actuals by month ● Eliminating large LEFT JOINs ● Eliminating an unnecessary join ● Using EXISTS ● Summarizing data ● Running totals ● Selecting latest status report ● Concatenating multi-valued lookup values into a string Interactive Examples
  • 14. www.regoconsulting.com Phone: 1-888-813-0444 14 Thank you. Questions Contact US 888.813.0444 Email Contact info@regoconsulting.com Web Site www.regoconsulting.com