Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Develop a SQL script to create a database with tables, views, roles, and functions. Form personalized offers to increase average check, frequency of visits, and cross-selling.

License

NotificationsYou must be signed in to change notification settings

Astrodynamic/RetailAnalitycs-in-postgresql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository contains scripts and functions for creating a database, creating views, managing user roles, and forming personal offers aimed at the growth of the average check, increasing the frequency of visits, and cross-selling.

Table of Contents

Database Creation

To create the database and tables described in the Input data, follow the steps below:

  1. Execute thepart1.sql script provided in the repository.
  2. This script will create the necessary tables and also include procedures for importing and exporting data for each table from/to CSV and TSV files.
  3. Make sure to upload the required CSV and TSV files from the datasets folder to the repository.

Views Creation

To create the views described in the Output data, follow the steps below:

  1. Execute thepart2.sql script provided in the repository.
  2. This script will create the views and include test queries for each view.

User Roles

To set up user roles and their permissions, follow the steps below:

  1. Execute thepart3.sql script provided in the repository.
  2. This script will create the roles and assign the following permissions:
    • Administrator: This role has full permissions to edit and view any information, as well as start and stop the processing.
    • Visitor: This role only has permission to view information of all tables.

Forming Personal Offers for Average Check Growth

To form personal offers aimed at the growth of the average check, follow the steps below:

  1. Execute thepart4.sql script provided in the repository.
  2. This script contains a function that determines offers based on the average check calculation method, first and last dates of the period, number of transactions, coefficient of average check increase, maximum churn index, maximum share of transactions with a discount, and allowable share of margin.
  3. The function will output the customer ID, average check target value, offer group, and maximum discount depth for each offer.

Forming Personal Offers for Increasing Frequency of Visits

To form personal offers aimed at increasing the frequency of visits, follow the steps below:

  1. Execute thepart5.sql script provided in the repository.
  2. This script contains a function that determines offers based on the first and last dates of the period, added number of transactions, maximum churn index, maximum share of transactions with a discount, and allowable margin share.
  3. The function will output the customer ID, period start date, period end date, target number of transactions, offer group, and maximum discount depth for each offer.

Forming Personal Offers for Cross-Selling

To form personal offers aimed at cross-selling, follow the steps below:

  1. Execute thepart6.sql script provided in the repository.
  2. This script contains a function that determines offers based on the number of groups, maximum churn index, maximum consumption stability index, maximum SKU share, and allowable margin share.
  3. The function will output the customer ID, SKU offers, and maximum discount depth for each offer.

Input Data

Personal information Table

FieldSystem field nameFormat / possible valuesDescription
Customer IDCustomer_ID------
NameCustomer_NameCyrillic, the first letter is capitalized, the rest are upper case, dashes and spaces are allowed---
SurnameCustomer_SurnameCyrillic, the first letter is capitalized, the rest are upper case, dashes and spaces are allowed---
Customer E-mailCustomer_Primary_EmailE-mail format---
Customer phone numberCustomer_Primary_Phone+7 and 10 Arabic numerals---

Cards Table

FieldSystem field nameFormat / possible valuesDescription
Card IDCustomer_Card_ID------
Customer IDCustomer_ID---One customer can own several cards

Transactions Table

FieldSystem field nameFormat / possible valuesDescription
Transaction IDTransaction_ID---Unique value
Card IDCustomer_Card_ID------
Transaction sumTransaction_SummArabic numeralTransaction sum in rubles(full purchase price excluding discounts)
Transaction dateTransaction_DateTimedd.mm.yyyy hh:mm:ssDate and time when the transaction was made
StoreTransaction_Store_IDStore IDThe store where the transaction was made

Checks Table

FieldSystem field nameFormat / possible valuesDescription
Transaction IDTransaction_ID---Transaction ID is specified for all products in the check
Product in the checkSKU_ID------
Number of pieces or kilogramsSKU_AmountArabic numeralThe quantity of the purchased product
Total amount for which the product was purchasedSKU_SummArabic numeralThe purchase amount of the actual volume of this product in rubles (full price without discounts and bonuses)
The paid price of the productSKU_Summ_PaidArabic numeralThe amount actually paid for the product not including the discount
Discount grantedSKU_DiscountArabic numeralThe size of the discount granted for the product in rubles

Product grid Table

FieldSystem field nameFormat / possible valuesDescription
Product IDSKU_ID------
Product nameSKU_NameCyrillic, Arabic numerals, special characters---
SKU groupGroup_ID---The ID of the group of related products to which the product belongs (for example, same type of yogurt of the same manufacturer and volume, but different flavors). One identifier is specified for all products in the group
Product purchase priceSKU_Purchase_PriceArabic numeralThe purchase price of the product for this store
Product retail priceSKU_Retail_PriceArabic numeralThe sale price of the product excluding discounts for this store

Stores Table

FieldSystem field nameFormat / possible valuesDescription
StoreTransaction_Store_ID------
Product IDSKU_ID------
Product purchase priceSKU_Purchase_PriceArabic numeralPurchasing price of products for this store
Product retail priceSKU_Retail_PriceArabic numeralThe sale price of the product excluding discounts for this store

SKU group Table

FieldSystem field nameFormat / possible valuesDescription
SKU groupGroup_ID------
Group nameGroup_NameCyrillic, Arabic numerals, special characters---

Date of analysis formation Table

FieldSystem field nameFormat / possible valuesDescription
Date of analysisAnalysis_Formationdd.mm.yyyy hh:mm:ss---

Output data

Customers View

FieldSystem field nameFormat / possible valuesDescription
Customer IDCustomer_ID---Unique value
Value of the average checkCustomer_Average_CheckArabic numeral, decimalValue of the average check in rubles for the analyzed period
Average check segmentCustomer_Average_Check_SegmentHigh; Middle; LowSegment description
Transaction frequency valueCustomer_FrequencyArabic numeral, decimalValue of customer visit frequency in the average number of days between transactions
Transaction frequency segmentCustomer_Frequency_SegmentOften; Occasionally; RarelySegment description
Number of days since the previous transactionCustomer_Inactive_PeriodArabic numeral, decimalNumber of days passed since the previous transaction date
Churn rateCustomer_Churn_RateArabic numeral, decimalValue of the customer churn rate
Churn rate segmentCustomer_Churn_SegmentHigh; Middle; LowSegment description
Segment numberCustomer_SegmentArabic numeralThe number of the segment to which the customer belongs
Main store IDCustomer_Primary_Store------

Purchase history View

FieldSystem field nameFormat / possible valuesDescription
Customer IDCustomer_ID------
Transaction IDTransaction_ID------
Transaction dateTransaction_DateTimedd.mm.yyyyy hh:mm:ss.0000000The date when the transaction was made
SKU groupGroup_ID---The ID of the group of related products to which the product belongs (for example, same type of yogurt of the same manufacturer and volume, but different flavors). One identifier is specified for all products in the group
Prime costGroup_CostArabic numeral, decimal---
Base retail priceGroup_SummArabic numeral, decimal---
Actual cost paidGroup_Summ_PaidArabic numeral, decimal---

Periods View

FieldSystem field nameFormat / possible valuesDescription
Customer IDCustomer_ID------
SKU groupGroup_ID---The ID of the group of related products to which the product belongs (for example, same type of yogurt of the same manufacturer and volume, but different flavors). One identifier is specified for all products in the group
Date of first purchase of the groupFirst_Group_Purchase_Dateyyyy-mm-dd hh:mm:ss.0000000---
Date of last purchase of the groupLast_Group_Purchase_Dateyyyy-mm-dd hh:mm:ss.0000000---
Number of transactions with the groupGroup_PurchaseArabic numeral, decimal---
Intensity of group purchasesGroup_FrequencyArabic numeral, decimal---
Minimum group discountGroup_Min_DiscountArabic numeral, decimal---

Groups View

FieldSystem field nameFormat / possible valuesDescription
Customer IDCustomer_ID------
Group IDGroup_ID------
Affinity indexGroup_Affinity_IndexArabic numeral, decimalCustomer affinity index for this group
Churn indexGroup_Churn_RateArabic numeral, decimalCustomer churn index for a specific group
Stability indexGroup_Stability_IndexArabic numeral, decimalIndicator demonstrating the stability of the customer consumption of the group
Actual margin for the groupGroup_MarginArabic numeral, decimalIndicator of the actual margin for the group for a particular customer
Share of transactions with a discountGroup_Discount_ShareArabic numeral, decimalShare of purchasing transactions of the group by a customer, within which the discount was applied (excluding the loyalty program bonuses)
Minimum size of the discountGroup_Minimum_DiscountArabic numeral, decimalMinimum size of the group discount for the customer
Average discountGroup_Average_DiscountArabic numeral, decimalAverage size of the group discount for the customer

License

This project is licensed under theMIT License. Feel free to use and modify the code according to your needs.

About

Develop a SQL script to create a database with tables, views, roles, and functions. Form personalized offers to increase average check, frequency of visits, and cross-selling.

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp