SQL
Mobile ticketing
Potential Resellers
Potential Resellers model for mobile ticketing.
source-preserved
Blocks
potential_resellers.sql · 71 lines
inferred
-- models/potential_resellers.sql
{{ config(materialized='view') }}
SELECT
o.OrderId as order_id, o.id as line_id, o.TransID, o.Status, o.Quantity, o.productid, o.producttype, o.CustomerID,
o.PricePaid, o.BookingFee, o.CommissionBack, o.PerformerCommissionBack, o.currencyid as list_currency_id, o.rate, o.Refunded, o.AttendeeFirstName, o.AttendeeLastName, o.AttendeeEmail,
tr.Date as OrderDate, tr.StoreId, tr.ChildAccountID, tr.currencyid as trans_currency_id, tr.InputCode as access_code, tr.UserIPAddr,
cb.Address1 as billing_address_1, cb.Address2 as billing_address_2, cb.County as billing_county, cb.CountryID as billing_country,
cb.Town as billing_town, cb.PostCode as billing_post_code, c.Address1, c.Address2, c.County, c.CountryID, c.Town, c.PostCode, c.Email as customers_email,
c.FirstName, c.LastName, c.DateAdded,
t.id as ticket_id, t.TicketLongName, t.SeatSection, t.SeatRow, t.SeatNo, IF(t.SeatRow IS NULL OR t.SeatRow = '', t.TicketLongName, t.SeatSection) as TicketName,
e.id as event_id, e.Date as EventDate, e.EventStatus, v.Name, v.TownCity, v.CountyRegion, v.Country, tours.Id as tour_id, tours.TourName, a.id as artist_id, a.Band as artist_name
FROM customer_purchases as o
LEFT JOIN transactions as tr ON o.orderid = tr.orderid
LEFT JOIN customers as c ON o.CustID = c.id
LEFT JOIN customers_bill as cb ON c.id = cb.CustID
LEFT JOIN event_entries as t ON o.productId = t.id
LEFT JOIN occasions as e ON t.eventid = e.id
LEFT JOIN venue as v on e.VenueId = v.Id
LEFT JOIN tours ON e.tourid = tours.id
LEFT JOIN music_group as a ON tours.music_groupid = a.id
WHERE o.ProductType = 'T' AND (tours.Id = 1873 OR tours.Id =1815 OR tours.Id =1823 OR tours.Id =1836 OR tours.Id =1616 OR tours.Id =1614 OR tours.Id =1782 OR tours.Id =1165 OR tours.Id =1757 OR tours.Id =1157 OR tours.Id =1254 OR tours.Id =1512 OR tours.Id =1731 OR tours.Id =1446 OR tours.Id =1708 OR tours.Id =1168 OR tours.Id =1358 OR tours.Id =1821 OR tours.Id =1432)
GROUP BY o.id
# models/schema.yml
version: 2
models:
- name: potential_resellers
columns:
- name: billing_address_concat
- name: potential_reseller
- name: potential_reseller_type
- name: order_id
- name: access_code
- name: ip_address
- name: line_id
- name: trans_id
- name: order_status
- name: event_entries_sold
- name: productid
- name: product_type
- name: customer_id
- name: price_paid
- name: booking_fee
- name: commission_back
- name: performer_commission_back
- name: amount
description: "This does not include shipping"
- name: list_currency_id
- name: trans_currency_id
- name: rate
- name: refunded
- name: store_id
- name: child_account_id
- name: billing_address_1
- name: billing_address_2
- name: billing_county
- name: billing_country
- name: billing_town
- name: billing_post_code
- name: first_name
- name: last_name
- name: address1
- name: address2
- name: county
- name: country_id
- name: town
- name: post_code
- name: customers_email
- name: ticket_id
Assumptions
- materialized='view' is the default; no persist hint found.
- schema.yml columns come from view dimensions; a primary_key dimension gets unique + not_null tests.
potential_resellers.sql · 20 lines
source-preserved
validation: parses
SELECT
o.OrderId as order_id, o.id as line_id, o.TransID, o.Status, o.Quantity, o.productid, o.producttype, o.CustomerID,
o.PricePaid, o.BookingFee, o.CommissionBack, o.PerformerCommissionBack, o.currencyid as list_currency_id, o.rate, o.Refunded, o.AttendeeFirstName, o.AttendeeLastName, o.AttendeeEmail,
tr.Date as OrderDate, tr.StoreId, tr.ChildAccountID, tr.currencyid as trans_currency_id, tr.InputCode as access_code, tr.UserIPAddr,
cb.Address1 as billing_address_1, cb.Address2 as billing_address_2, cb.County as billing_county, cb.CountryID as billing_country,
cb.Town as billing_town, cb.PostCode as billing_post_code, c.Address1, c.Address2, c.County, c.CountryID, c.Town, c.PostCode, c.Email as customers_email,
c.FirstName, c.LastName, c.DateAdded,
t.id as ticket_id, t.TicketLongName, t.SeatSection, t.SeatRow, t.SeatNo, IF(t.SeatRow IS NULL OR t.SeatRow = '', t.TicketLongName, t.SeatSection) as TicketName,
e.id as event_id, e.Date as EventDate, e.EventStatus, v.Name, v.TownCity, v.CountyRegion, v.Country, tours.Id as tour_id, tours.TourName, a.id as artist_id, a.Band as artist_name
FROM customer_purchases as o
LEFT JOIN transactions as tr ON o.orderid = tr.orderid
LEFT JOIN customers as c ON o.CustID = c.id
LEFT JOIN customers_bill as cb ON c.id = cb.CustID
LEFT JOIN event_entries as t ON o.productId = t.id
LEFT JOIN occasions as e ON t.eventid = e.id
LEFT JOIN venue as v on e.VenueId = v.Id
LEFT JOIN tours ON e.tourid = tours.id
LEFT JOIN music_group as a ON tours.music_groupid = a.id
WHERE o.ProductType = 'T' AND (tours.Id = 1873 OR tours.Id =1815 OR tours.Id =1823 OR tours.Id =1836 OR tours.Id =1616 OR tours.Id =1614 OR tours.Id =1782 OR tours.Id =1165 OR tours.Id =1757 OR tours.Id =1157 OR tours.Id =1254 OR tours.Id =1512 OR tours.Id =1731 OR tours.Id =1446 OR tours.Id =1708 OR tours.Id =1168 OR tours.Id =1358 OR tours.Id =1821 OR tours.Id =1432)
GROUP BY o.id
potential_resellers.view.lkml · 363 lines
inferred
view: potential_resellers {
derived_table: {
sql: SELECT
o.OrderId as order_id, o.id as line_id, o.TransID, o.Status, o.Quantity, o.productid, o.producttype, o.CustomerID,
o.PricePaid, o.BookingFee, o.CommissionBack, o.PerformerCommissionBack, o.currencyid as list_currency_id, o.rate, o.Refunded, o.AttendeeFirstName, o.AttendeeLastName, o.AttendeeEmail,
tr.Date as OrderDate, tr.StoreId, tr.ChildAccountID, tr.currencyid as trans_currency_id, tr.InputCode as access_code, tr.UserIPAddr,
cb.Address1 as billing_address_1, cb.Address2 as billing_address_2, cb.County as billing_county, cb.CountryID as billing_country,
cb.Town as billing_town, cb.PostCode as billing_post_code, c.Address1, c.Address2, c.County, c.CountryID, c.Town, c.PostCode, c.Email as customers_email,
c.FirstName, c.LastName, c.DateAdded,
t.id as ticket_id, t.TicketLongName, t.SeatSection, t.SeatRow, t.SeatNo, IF(t.SeatRow IS NULL OR t.SeatRow = '', t.TicketLongName, t.SeatSection) as TicketName,
e.id as event_id, e.Date as EventDate, e.EventStatus, v.Name, v.TownCity, v.CountyRegion, v.Country, tours.Id as tour_id, tours.TourName, a.id as artist_id, a.Band as artist_name
FROM customer_purchases as o
LEFT JOIN transactions as tr ON o.orderid = tr.orderid
LEFT JOIN customers as c ON o.CustID = c.id
LEFT JOIN customers_bill as cb ON c.id = cb.CustID
LEFT JOIN event_entries as t ON o.productId = t.id
LEFT JOIN occasions as e ON t.eventid = e.id
LEFT JOIN venue as v on e.VenueId = v.Id
LEFT JOIN tours ON e.tourid = tours.id
LEFT JOIN music_group as a ON tours.music_groupid = a.id
WHERE o.ProductType = 'T' AND (tours.Id = 1873 OR tours.Id =1815 OR tours.Id =1823 OR tours.Id =1836 OR tours.Id =1616 OR tours.Id =1614 OR tours.Id =1782 OR tours.Id =1165 OR tours.Id =1757 OR tours.Id =1157 OR tours.Id =1254 OR tours.Id =1512 OR tours.Id =1731 OR tours.Id =1446 OR tours.Id =1708 OR tours.Id =1168 OR tours.Id =1358 OR tours.Id =1821 OR tours.Id =1432)
GROUP BY o.id ;;
}
dimension: billing_address_concat {
sql: CONCAT(${billing_address_1}, ${billing_address_2}, ${billing_town}, ${billing_country}) ;;
}
dimension: potential_reseller {
type: yesno
sql: CASE
WHEN ${potential_resellers_billing_address.address_concat} IS NULL AND ${potential_resellers_email.email} IS NULL THEN 0
ELSE 1
END ;;
}
dimension: potential_reseller_type {
sql: CASE
WHEN ${potential_resellers_billing_address.address_concat} IS NOT NULL AND ${potential_resellers_email.email} IS NOT NULL
THEN "Billing & Email Address"
WHEN ${potential_resellers_billing_address.address_concat} IS NOT NULL AND ${potential_resellers_email.email} IS NULL
THEN "Billing Address"
WHEN ${potential_resellers_billing_address.address_concat} IS NULL AND ${potential_resellers_email.email} IS NOT NULL
THEN "Email Address"
ELSE "Not a Reseller"
END ;;
}
dimension: order_id {
type: string
sql: ${TABLE}.order_id ;;
}
dimension: access_code {
sql: ${TABLE}.access_code ;;
}
dimension: ip_address {
sql: ${TABLE}.UserIPAddr ;;
}
dimension: line_id {
type: int
sql: ${TABLE}.line_id ;;
}
dimension: trans_id {
type: int
sql: ${TABLE}.TransID ;;
}
dimension: order_status {
type: string
sql: ${TABLE}.Status ;;
}
dimension: event_entries_sold {
type: int
sql: ${TABLE}.Quantity ;;
}
dimension: productid {
type: int
sql: ${TABLE}.productid ;;
}
dimension: product_type {
type: string
sql: ${TABLE}.producttype ;;
}
dimension: customer_id {
type: string
sql: ${TABLE}.CustomerID ;;
}
dimension: price_paid {
type: number
sql: ${TABLE}.PricePaid ;;
}
dimension: booking_fee {
type: number
sql: ${TABLE}.BookingFee ;;
}
dimension: commission_back {
type: number
sql: ${TABLE}.CommissionBack ;;
}
dimension: performer_commission_back {
type: number
sql: ${TABLE}.PerformerCommissionBack ;;
}
dimension: amount {
label: "Amount (List)"
description: "This does not include shipping"
type: number
sql: ${price_paid} + ${booking_fee} + ${commission_back} + ${performer_commission_back} ;;
}
dimension: list_currency_id {
type: int
sql: ${TABLE}.list_currency_id ;;
}
dimension: trans_currency_id {
type: int
sql: ${TABLE}.trans_currency_id ;;
}
dimension: rate {
type: number
sql: ${TABLE}.rate ;;
}
dimension: refunded {
type: string
sql: ${TABLE}.Refunded ;;
}
dimension: store_id {
type: int
sql: ${TABLE}.StoreId ;;
}
dimension: child_account_id {
type: int
sql: ${TABLE}.ChildAccountID ;;
}
dimension: billing_address_1 {
type: string
sql: ${TABLE}.billing_address_1 ;;
}
dimension: billing_address_2 {
type: string
sql: ${TABLE}.billing_address_2 ;;
}
dimension: billing_county {
type: string
sql: ${TABLE}.billing_county ;;
}
dimension: billing_country {
type: int
sql: ${TABLE}.billing_country ;;
}
dimension: billing_town {
type: string
sql: ${TABLE}.billing_town ;;
}
dimension: billing_post_code {
type: string
sql: ${TABLE}.billing_post_code ;;
}
dimension: first_name {
sql: ${TABLE}.FirstName ;;
}
dimension: last_name {
sql: ${TABLE}.LastName ;;
}
dimension: address1 {
type: string
sql: ${TABLE}.Address1 ;;
}
dimension: address2 {
type: string
sql: ${TABLE}.Address2 ;;
}
dimension: county {
type: string
sql: ${TABLE}.County ;;
}
dimension: country_id {
type: int
sql: ${TABLE}.CountryID ;;
}
dimension: town {
type: string
sql: ${TABLE}.Town ;;
}
dimension: post_code {
type: string
sql: ${TABLE}.PostCode ;;
}
dimension: customers_email {
sql: ${TABLE}.customers_email ;;
}
dimension: ticket_id {
type: int
sql: ${TABLE}.ticket_id ;;
}
dimension: ticket_long_name {
type: string
sql: ${TABLE}.TicketLongName ;;
}
dimension: seat_section {
type: string
sql: ${TABLE}.SeatSection ;;
}
dimension: seat_row {
type: string
sql: ${TABLE}.SeatRow ;;
}
dimension: seat_no {
type: int
sql: ${TABLE}.SeatNo ;;
}
dimension: ticket_name {
type: string
sql: ${TABLE}.TicketName ;;
}
dimension: event_id {
sql: ${TABLE}.event_id ;;
}
dimension: event_status {
type: string
sql: ${TABLE}.EventStatus ;;
}
dimension: venue_name {
type: string
sql: ${TABLE}.Name ;;
}
dimension: venue_town {
type: string
sql: ${TABLE}.TownCity ;;
}
dimension: venue_county {
type: string
sql: ${TABLE}.CountyRegion ;;
}
dimension: venue_country {
type: string
sql: ${TABLE}.Country ;;
}
dimension: venue_id {
type: int
sql: ${TABLE}.venue_id ;;
}
dimension: tour_id {
type: int
sql: ${TABLE}.tour_id ;;
}
dimension: tour_name {
type: string
sql: ${TABLE}.TourName ;;
}
dimension: artist_id {
type: int
sql: ${TABLE}.artist_id ;;
}
dimension: artist_name {
type: string
sql: ${TABLE}.artist_name ;;
}
dimension_group: attendee_first_name {
type: time
sql: ${TABLE}.AttendeeFirstName ;;
}
dimension_group: attendee_last_name {
type: time
sql: ${TABLE}.AttendeeLastName ;;
}
dimension_group: attendee_email {
type: time
sql: ${TABLE}.AttendeeEmail ;;
}
dimension_group: order {
type: time
timeframes: [time, date, week, month]
sql: ${TABLE}.OrderDate ;;
}
dimension_group: account_create {
type: time
timeframes: [time, date, week, month]
sql: ${TABLE}.DateAdded ;;
}
dimension_group: event {
type: time
timeframes: [time, date, week, month]
sql: ${TABLE}.EventDate ;;
}
measure: count {
type: count
drill_fields: [detail*]
}
measure: total_event_entries_sold {
type: sum
sql: ${event_entries_sold} ;;
}
measure: total_amount {
label: "Total Amount (List)"
description: "This does not include shipping"
type: sum
sql: ${amount} ;;
}
measure: ticket_list {
type: list
}
}
potential_resellers.view.lookml · 243 lines
source-preserved
- view: potential_resellers
derived_table:
sql: SELECT
o.OrderId as order_id, o.id as line_id, o.TransID, o.Status, o.Quantity, o.productid, o.producttype, o.CustomerID,
o.PricePaid, o.BookingFee, o.CommissionBack, o.PerformerCommissionBack, o.currencyid as list_currency_id, o.rate, o.Refunded, o.AttendeeFirstName, o.AttendeeLastName, o.AttendeeEmail,
tr.Date as OrderDate, tr.StoreId, tr.ChildAccountID, tr.currencyid as trans_currency_id, tr.InputCode as access_code, tr.UserIPAddr,
cb.Address1 as billing_address_1, cb.Address2 as billing_address_2, cb.County as billing_county, cb.CountryID as billing_country,
cb.Town as billing_town, cb.PostCode as billing_post_code, c.Address1, c.Address2, c.County, c.CountryID, c.Town, c.PostCode, c.Email as customers_email,
c.FirstName, c.LastName, c.DateAdded,
t.id as ticket_id, t.TicketLongName, t.SeatSection, t.SeatRow, t.SeatNo, IF(t.SeatRow IS NULL OR t.SeatRow = '', t.TicketLongName, t.SeatSection) as TicketName,
e.id as event_id, e.Date as EventDate, e.EventStatus, v.Name, v.TownCity, v.CountyRegion, v.Country, tours.Id as tour_id, tours.TourName, a.id as artist_id, a.Band as artist_name
FROM customer_purchases as o
LEFT JOIN transactions as tr ON o.orderid = tr.orderid
LEFT JOIN customers as c ON o.CustID = c.id
LEFT JOIN customers_bill as cb ON c.id = cb.CustID
LEFT JOIN event_entries as t ON o.productId = t.id
LEFT JOIN occasions as e ON t.eventid = e.id
LEFT JOIN venue as v on e.VenueId = v.Id
LEFT JOIN tours ON e.tourid = tours.id
LEFT JOIN music_group as a ON tours.music_groupid = a.id
WHERE o.ProductType = 'T' AND (tours.Id = 1873 OR tours.Id =1815 OR tours.Id =1823 OR tours.Id =1836 OR tours.Id =1616 OR tours.Id =1614 OR tours.Id =1782 OR tours.Id =1165 OR tours.Id =1757 OR tours.Id =1157 OR tours.Id =1254 OR tours.Id =1512 OR tours.Id =1731 OR tours.Id =1446 OR tours.Id =1708 OR tours.Id =1168 OR tours.Id =1358 OR tours.Id =1821 OR tours.Id =1432)
GROUP BY o.id
fields:
- dimension: billing_address_concat
sql: CONCAT(${billing_address_1}, ${billing_address_2}, ${billing_town}, ${billing_country})
- dimension: potential_reseller
type: yesno
sql: CASE
WHEN ${potential_resellers_billing_address.address_concat} IS NULL AND ${potential_resellers_email.email} IS NULL THEN 0
ELSE 1
END
- dimension: potential_reseller_type
sql: CASE
WHEN ${potential_resellers_billing_address.address_concat} IS NOT NULL AND ${potential_resellers_email.email} IS NOT NULL
THEN "Billing & Email Address"
WHEN ${potential_resellers_billing_address.address_concat} IS NOT NULL AND ${potential_resellers_email.email} IS NULL
THEN "Billing Address"
WHEN ${potential_resellers_billing_address.address_concat} IS NULL AND ${potential_resellers_email.email} IS NOT NULL
THEN "Email Address"
ELSE "Not a Reseller"
END
- dimension: order_id
type: string
sql: ${TABLE}.order_id
- dimension: access_code
sql: ${TABLE}.access_code
- dimension: ip_address
sql: ${TABLE}.UserIPAddr
- dimension: line_id
type: int
sql: ${TABLE}.line_id
- dimension: trans_id
type: int
sql: ${TABLE}.TransID
- dimension: order_status
type: string
sql: ${TABLE}.Status
- dimension: event_entries_sold
type: int
sql: ${TABLE}.Quantity
- dimension: productid
type: int
sql: ${TABLE}.productid
- dimension: product_type
type: string
sql: ${TABLE}.producttype
- dimension: customer_id
type: string
sql: ${TABLE}.CustomerID
- dimension: price_paid
type: number
sql: ${TABLE}.PricePaid
- dimension: booking_fee
type: number
sql: ${TABLE}.BookingFee
- dimension: commission_back
type: number
sql: ${TABLE}.CommissionBack
- dimension: performer_commission_back
type: number
sql: ${TABLE}.PerformerCommissionBack
- dimension: amount
type: number
label: Amount (List)
description: This does not include shipping
sql: ${price_paid} + ${booking_fee} + ${commission_back} + ${performer_commission_back}
- dimension: list_currency_id
type: int
sql: ${TABLE}.list_currency_id
- dimension: trans_currency_id
type: int
sql: ${TABLE}.trans_currency_id
- dimension: rate
type: number
sql: ${TABLE}.rate
- dimension: refunded
type: string
sql: ${TABLE}.Refunded
- dimension: store_id
type: int
sql: ${TABLE}.StoreId
- dimension: child_account_id
type: int
sql: ${TABLE}.ChildAccountID
- dimension: billing_address_1
type: string
sql: ${TABLE}.billing_address_1
- dimension: billing_address_2
type: string
sql: ${TABLE}.billing_address_2
- dimension: billing_county
type: string
sql: ${TABLE}.billing_county
- dimension: billing_country
type: int
sql: ${TABLE}.billing_country
- dimension: billing_town
type: string
sql: ${TABLE}.billing_town
- dimension: billing_post_code
type: string
sql: ${TABLE}.billing_post_code
- dimension: first_name
sql: ${TABLE}.FirstName
- dimension: last_name
sql: ${TABLE}.LastName
- dimension: address1
type: string
sql: ${TABLE}.Address1
- dimension: address2
type: string
sql: ${TABLE}.Address2
- dimension: county
type: string
sql: ${TABLE}.County
- dimension: country_id
type: int
sql: ${TABLE}.CountryID
- dimension: town
type: string
sql: ${TABLE}.Town
- dimension: post_code
type: string
sql: ${TABLE}.PostCode
- dimension: customers_email
sql: ${TABLE}.customers_email
- dimension: ticket_id
type: int
sql: ${TABLE}.ticket_id
- dimension: ticket_long_name
type: string
sql: ${TABLE}.TicketLongName
- dimension: seat_section
type: string
sql: ${TABLE}.SeatSection
- dimension: seat_row
type: string
sql: ${TABLE}.SeatRow
- dimension: seat_no
type: int
sql: ${TABLE}.SeatNo
- dimension: ticket_name
type: string
sql: ${TABLE}.TicketName
- dimension: event_id
sql: ${TABLE}.event_id
- dimension: event_status
type: string
sql: ${TABLE}.EventStatus
- dimension: venue_name
type: string
sql: ${TABLE}.Name
- dimension: venue_town
type: string
sql: ${TABLE}.TownCity
- dimension: venue_county
type: string
sql: ${TABLE}.CountyRegion
- dimension: venue_country
type: string
sql: ${TABLE}.Country
- dimension: venue_id
type: int
sql: ${TABLE}.venue_id
- dimension: tour_id
type: int
sql: ${TABLE}.tour_id
- dimension: tour_name
type: string
sql: ${TABLE}.TourName
- dimension: artist_id
type: int
sql: ${TABLE}.artist_id
- dimension: artist_name
type: string
sql: ${TABLE}.artist_name
- dimension_group: attendee_first_name
type: time
sql: ${TABLE}.AttendeeFirstName
- dimension_group: attendee_last_name
type: time
sql: ${TABLE}.AttendeeLastName
- dimension_group: attendee_email
type: time
sql: ${TABLE}.AttendeeEmail
- dimension_group: order
type: time
timeframes:
- time
- date
- week
- month
sql: ${TABLE}.OrderDate
- dimension_group: account_create
type: time
timeframes:
- time
- date
- week
- month
sql: ${TABLE}.DateAdded
- dimension_group: event
type: time
timeframes:
- time
- date
- week
- month
sql: ${TABLE}.EventDate
- measure: count
type: count
drill_fields:
- detail*
- measure: total_event_entries_sold
type: sum
sql: ${event_entries_sold}
- measure: total_amount
type: sum
label: Total Amount (List)
description: This does not include shipping
sql: ${amount}
- measure: ticket_list
type: list
Contents
- potential_resellers.sql
- potential_resellers.sql
- potential_resellers.view.lkml
- potential_resellers.view.lookml