-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Exploring Your Ecommerce Dataset with SQL in Google BigQuery
- Loading branch information
1 parent
e2ef287
commit d6d0b53
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
Exploring Your Ecommerce Dataset with SQL in Google BigQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
bq query --use_legacy_sql=false \ | ||
'SELECT COUNT(*) as num_duplicate_rows, * FROM | ||
`data-to-insights.ecommerce.all_sessions_raw` | ||
GROUP BY | ||
fullVisitorId, channelGrouping, time, country, city, totalTransactionRevenue, transactions, timeOnSite, pageviews, sessionQualityDim, date, visitId, type, productRefundAmount, productQuantity, productPrice, productRevenue, productSKU, v2ProductName, v2ProductCategory, productVariant, currencyCode, itemQuantity, itemRevenue, transactionRevenue, transactionId, pageTitle, searchKeyword, pagePathLevel1, eCommerceAction_type, eCommerceAction_step, eCommerceAction_option | ||
HAVING num_duplicate_rows > 1;' | ||
bq query --use_legacy_sql=false \ | ||
'SELECT | ||
fullVisitorId, | ||
visitId, | ||
date, | ||
time, | ||
v2ProductName, | ||
productSKU, | ||
type, | ||
eCommerceAction_type, | ||
eCommerceAction_step, | ||
eCommerceAction_option, | ||
transactionRevenue, | ||
transactionId, | ||
COUNT(*) as row_count | ||
FROM | ||
`data-to-insights.ecommerce.all_sessions` | ||
GROUP BY 1,2,3 ,4, 5, 6, 7, 8, 9, 10,11,12 | ||
HAVING row_count > 1 # find duplicates' | ||
bq query --use_legacy_sql=false \ | ||
'#standardSQL | ||
SELECT | ||
COUNT(*) AS product_views, | ||
COUNT(DISTINCT fullVisitorId) AS unique_visitors | ||
FROM `data-to-insights.ecommerce.all_sessions`;' | ||
bq query --use_legacy_sql=false \ | ||
'SELECT | ||
COUNT(DISTINCT fullVisitorId) AS unique_visitors, | ||
channelGrouping | ||
FROM `data-to-insights.ecommerce.all_sessions` | ||
GROUP BY channelGrouping | ||
ORDER BY channelGrouping DESC;' | ||
bq query --use_legacy_sql=false \ | ||
'SELECT | ||
(v2ProductName) AS ProductName | ||
FROM `data-to-insights.ecommerce.all_sessions` | ||
GROUP BY ProductName | ||
ORDER BY ProductName' | ||
bq query --use_legacy_sql=false \ | ||
'SELECT | ||
COUNT(*) AS product_views, | ||
(v2ProductName) AS ProductName | ||
FROM `data-to-insights.ecommerce.all_sessions` | ||
WHERE type = "PAGE" | ||
GROUP BY v2ProductName | ||
ORDER BY product_views DESC | ||
LIMIT 5;' | ||
bq query --use_legacy_sql=false \ | ||
'WITH unique_product_views_by_person AS ( | ||
-- find each unique product viewed by each visitor | ||
SELECT | ||
fullVisitorId, | ||
(v2ProductName) AS ProductName | ||
FROM `data-to-insights.ecommerce.all_sessions` | ||
WHERE type = "PAGE" | ||
GROUP BY fullVisitorId, v2ProductName ) | ||
-- aggregate the top viewed products and sort them | ||
SELECT | ||
COUNT(*) AS unique_view_count, | ||
ProductName | ||
FROM unique_product_views_by_person | ||
GROUP BY ProductName | ||
ORDER BY unique_view_count DESC | ||
LIMIT 5' | ||
bq query --use_legacy_sql=false \ | ||
'SELECT | ||
COUNT(*) AS product_views, | ||
COUNT(productQuantity) AS orders, | ||
SUM(productQuantity) AS quantity_product_ordered, | ||
v2ProductName | ||
FROM `data-to-insights.ecommerce.all_sessions` | ||
WHERE type = "PAGE" | ||
GROUP BY v2ProductName | ||
ORDER BY product_views DESC | ||
LIMIT 5;' | ||
bq query --use_legacy_sql=false \ | ||
'SELECT | ||
COUNT(*) AS product_views, | ||
COUNT(productQuantity) AS orders, | ||
SUM(productQuantity) AS quantity_product_ordered, | ||
SUM(productQuantity) / COUNT(productQuantity) AS avg_per_order, | ||
(v2ProductName) AS ProductName | ||
FROM `data-to-insights.ecommerce.all_sessions` | ||
WHERE type = "PAGE" | ||
GROUP BY v2ProductName | ||
ORDER BY product_views DESC | ||
LIMIT 5;' |