Sample
Queries
Ready-to-use SQL queries for exploring AdventureWorks data. Copy, modify, and run these queries to understand your bicycle business data.
Query Categories
Explore 16 sample queries organized by business function
Sales Analysis
2 queries
Channel Sales
1 queries
Financial Analysis
2 queries
Inventory Management
2 queries
Product Information
2 queries
Operations
1 queries
Internet Sales Overview
Sales AnalysisThis query retrieves key details of online sales transactions, including customer, product, and territory information.
SELECT
f.SalesOrderNumber,
dDate.CalendarYear,
dCustomer.FirstName + ' ' + dCustomer.LastName AS CustomerName,
dProduct.EnglishProductName,
dSalesTerritory.SalesTerritoryRegion,
f.OrderQuantity,
f.UnitPrice,
f.SalesAmount
FROM
FactInternetSales AS f
JOIN
DimDate AS dDate ON f.OrderDateKey = dDate.DateKey
JOIN
DimCustomer AS dCustomer ON f.CustomerKey = dCustomer.CustomerKey
JOIN
DimProduct AS dProduct ON f.ProductKey = dProduct.ProductKey
JOIN
DimSalesTerritory AS dSalesTerritory ON f.SalesTerritoryKey = dSalesTerritory.SalesTerritoryKey;
Reseller Sales Overview
Channel SalesThis query focuses on sales made through resellers, providing insights into reseller names, products, and sales territories.
SELECT
f.SalesOrderNumber,
dDate.CalendarYear,
dReseller.ResellerName,
dProduct.EnglishProductName,
dSalesTerritory.SalesTerritoryCountry,
f.OrderQuantity,
f.SalesAmount
FROM
FactResellerSales AS f
JOIN
DimDate AS dDate ON f.OrderDateKey = dDate.DateKey
JOIN
DimReseller AS dReseller ON f.ResellerKey = dReseller.ResellerKey
JOIN
DimProduct AS dProduct ON f.ProductKey = dProduct.ProductKey
JOIN
DimSalesTerritory AS dSalesTerritory ON f.SalesTerritoryKey = dSalesTerritory.SalesTerritoryKey;
Call Center Daily Performance
OperationsThis query extracts operational metrics for the call center, useful for tracking daily performance.
SELECT
dDate.FullDateAlternateKey AS ReportDate,
f.Calls,
f.TotalOperators,
f.ServiceGrade
FROM
FactCallCenter AS f
JOIN
DimDate AS dDate ON f.DateKey = dDate.DateKey;
Product Inventory Movements
Inventory ManagementThis query provides a detailed view of product inventory changes, showing units received, shipped, and current balance.
SELECT
f.MovementDate,
dProduct.EnglishProductName,
f.UnitsIn,
f.UnitsOut,
f.UnitsBalance
FROM
FactProductInventory AS f
JOIN
DimProduct AS dProduct ON f.ProductKey = dProduct.ProductKey
JOIN
DimDate AS dDate ON f.DateKey = dDate.DateKey;
Financial Transactions
Financial AnalysisThis query allows for an overview of financial transactions, categorized by organization, department, scenario, and account type.
SELECT
dDate.FullDateAlternateKey AS TransactionDate,
dOrganization.OrganizationName,
dDepartmentGroup.DepartmentGroupName,
dScenario.ScenarioName,
dAccount.AccountDescription,
f.Amount
FROM
FactFinance AS f
JOIN
DimDate AS dDate ON f.DateKey = dDate.DateKey
JOIN
DimOrganization AS dOrganization ON f.OrganizationKey = dOrganization.OrganizationKey
JOIN
DimDepartmentGroup AS dDepartmentGroup ON f.DepartmentGroupKey = dDepartmentGroup.DepartmentGroupKey
JOIN
DimScenario AS dScenario ON f.ScenarioKey = dScenario.ScenarioKey
JOIN
DimAccount AS dAccount ON f.AccountKey = dAccount.AccountKey;
Sales Quotas by Employee
Performance TrackingThis query retrieves sales quota information, linking employees to their annual and quarterly targets.
SELECT
dEmployee.FirstName + ' ' + dEmployee.LastName AS EmployeeName,
dDate.CalendarYear,
dDate.CalendarQuarter,
f.SalesAmountQuota
FROM
FactSalesQuota AS f
JOIN
DimEmployee AS dEmployee ON f.EmployeeKey = dEmployee.EmployeeKey
JOIN
DimDate AS dDate ON f.DateKey = dDate.DateKey;
Survey Responses Summary
Customer FeedbackThis query aggregates customer survey responses, providing counts by date, customer, and product category.
SELECT
dDate.FullDateAlternateKey AS SurveyDate,
dCustomer.FirstName + ' ' + dCustomer.LastName AS CustomerName,
dProductCategory.EnglishProductCategoryName,
COUNT(*) AS ResponseCount
FROM
FactSurveyResponse AS f
JOIN
DimCustomer AS dCustomer ON f.CustomerKey = dCustomer.CustomerKey
JOIN
DimProductCategory AS dProductCategory ON f.ProductCategoryKey = dProductCategory.ProductCategoryKey
JOIN
DimDate AS dDate ON f.DateKey = dDate.DateKey
GROUP BY
dDate.FullDateAlternateKey, dCustomer.FirstName, dCustomer.LastName, dProductCategory.EnglishProductCategoryName;
Daily Currency Exchange Rates
Financial AnalysisThis query provides a snapshot of average and end-of-day currency exchange rates for specific dates.
SELECT
dDate.FullDateAlternateKey AS RateDate,
f.CurrencyKey,
f.AverageRate,
f.EndOfDayRate
FROM
FactCurrencyRate AS f
JOIN
DimDate AS dDate ON f.DateKey = dDate.DateKey;
Product Inventory Summary
Inventory ManagementThis query summarizes total units in and out for each product, useful for high-level inventory tracking.
SELECT
dProduct.EnglishProductName,
SUM(f.UnitsIn) AS TotalUnitsIn,
SUM(f.UnitsOut) AS TotalUnitsOut
FROM
FactProductInventory AS f
JOIN
DimProduct AS dProduct ON f.ProductKey = dProduct.ProductKey
GROUP BY
dProduct.EnglishProductName;
International Product Descriptions
Product InformationThis query helps to retrieve localized product descriptions for multi-lingual reporting.
SELECT
f.ProductKey,
dProduct.EnglishProductName,
f.CultureName,
f.ProductDescription
FROM
FactAdditionalInternationalProductDescription AS f
JOIN
DimProduct AS dProduct ON f.ProductKey = dProduct.ProductKey;
Internet Sales Reasons
Sales AnalysisThis query links internet sales orders to the specific reasons or promotions that influenced the purchase.
SELECT
f.SalesOrderNumber,
f.SalesOrderLineNumber,
dSalesReason.SalesReasonName
FROM
FactInternetSalesReason AS f
JOIN
DimSalesReason AS dSalesReason ON f.SalesReasonKey = dSalesReason.SalesReasonKey;
Currency Dimension Lookup
Reference DataA simple lookup query for currency names and their keys.
SELECT
dCurrency.CurrencyKey,
dCurrency.CurrencyName
FROM
DimCurrency AS dCurrency;
Product Subcategory Details
Product InformationThis query shows the hierarchical relationship between product subcategories and their parent categories.
SELECT
dSub.ProductSubcategoryKey,
dSub.EnglishProductSubcategoryName,
dCat.EnglishProductCategoryName AS ParentCategory
FROM
DimProductSubcategory AS dSub
JOIN
DimProductCategory AS dCat ON dSub.ProductCategoryKey = dCat.ProductCategoryKey;
Promotions Overview
MarketingThis query provides a summary of all available promotional campaigns, including their discount percentages and validity dates.
SELECT
dPromo.PromotionKey,
dPromo.EnglishPromotionName,
dPromo.DiscountPct,
dPromo.StartDate,
dPromo.EndDate
FROM
DimPromotion AS dPromo;
Geographic Details
Geographic AnalysisThis query provides detailed geographic information, useful for sales territory and customer location analysis.
SELECT
dGeo.GeographyKey,
dGeo.City,
dGeo.StateProvinceName,
dGeo.EnglishCountryRegionName AS Country
FROM
DimGeography AS dGeo;
Prospective Buyers Information
Lead ManagementThis query retrieves contact and demographic information for potential customers.
SELECT
pb.ProspectiveBuyerKey,
pb.FirstName + ' ' + pb.LastName AS BuyerName,
pb.EmailAddress,
pb.YearlyIncome,
pb.City,
pb.StateProvinceCode
FROM
ProspectiveBuyer AS pb;
Ready to Analyze?
Now that you have the queries, discover key business questions to unlock powerful insights from your data.