This SQL query is designed to extract and aggregate information...
This SQL query is designed to extract and aggregate information about "opt-outs" from a sales-related dataset. Here's a breakdown of what the code does:
-
Purpose: The query retrieves data about quotes for clients who may have requested "opt-outs" in the sales process, including details such as submission dates, opt-out statuses, onboarding methods, sales office regions, and associated employee details like managers and sales associates.
-
Columns Selected:
- Provides information about the quotes (
quote.QUOTE_NUMBER
,quote.DATEOFORDERSUBMISSION_QUOTE
, etc.). - Includes specific attributes of opt-outs, like opt-out status (
quote.EVOOPTOUTSTATUS_QUOTE
), opt-out reason (quote.EVOELIGIBILTYOPTOUTMESSAGE
), and whether opt-out was requested or eligible. - Includes sales personnel and organizational hierarchy (
office.se_name
,office.vp_name
, etc.). - Computes:
"Opt-out Count"
: A count of quotes where the opt-out status is "Approved"."Eligible Count"
: A count of quotes that are ineligible (EVOOPTOUTSTATUS_QUOTE
isnull
or "Rejected")."Digital Count"
: Quotes with onboarding methods related to digital processes (Digital
orDigitalPlus
).
- Provides information about the quotes (
-
Data Sources:
- The main data is extracted from the table
self_service.sv_cpq_mas_sbs_nas_can_quote
(aliased asquote
). - Joins additional data:
self_service.sv_sfdc_users
for user details (matching onPREPAREDBY_NAME
).sales_dw.officemap
for office details (matching onSALESOFFICECODE_QUOTE
).
- The main data is extracted from the table
-
Subquery:
- There is a subquery that identifies the maximum submission date for each quote (
maxdate
). This ensures only the most recent submission date for each quote is included in the final result.
- There is a subquery that identifies the maximum submission date for each quote (
-
Filters: The
WHERE
clause applies several filters to ensure only relevant data is processed:- The
HASRUN_QUOTE
field must be'TRUE'
. - Excludes rows from specific processing centers.
- Filters for specific order types (
NEW CLIENT
orADDITIONAL CONTROL
). - Limits the submission date between
07/01/2022
and the current date. - Ensures rows have a
CREATEDDATE_QUOTE
after2022.07.01
(converted to format'yyyy.MM.dd'
).
- The
-
Grouping: The query uses
GROUP BY
to aggregate and organize the data by fields relevant to the quotes and summary counts.
Summary:
This query pulls a detailed report on opt-out requests associated with quotes in the sales system. It filters out irrelevant data, calculates summary fields (e.g., counts for opt-outs, eligibility, and digital methods), and joins additional metadata like user and office details. It is useful for analyzing opt-out trends and their associated sales characteristics over a specific timeframe.