Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

postgreSQL - PART 1 : Creating a table using the following attributes: sale _ date,sale _ year,sale _ month,age,gender,country,state,category,sub _ category,quantity,unit _ cost , unit

postgreSQL - PART 1: Creating a table using the following attributes: sale_date,sale_year,sale_month,age,gender,country,state,category,sub_category,quantity,unit_cost,unit_price,cost,revenue: Please use the following instructions: PART 1 Creating the Table and Importing the Data
1. Create the table with appropriate data types
a. Name the table customer_spending
b. Reuse the column titles from the csv, do not change these
c. When selecting data types for your tables, ensure they accommodate the full
range of values and avoid truncating any values. Ensure that decimals, lengths,
and other specifications are sufficient for all data to be imported completely.
i. You must declare precision and scale when applicable.
ii. Go bigger if needed- you will not lose points for adding extra space but
you will lose points if your data types do not accommodate all values. PART 2: Please note that column names in bold to help you identify the columns from the table to be
used in each question. However, these aren't necessarily the columns that your query output
should return. Be sure to read each question carefully. Ensure results show all expected
decimal places unless otherwise specified! Remember, the data types you declared can
influence the outcome of your calculations in PostgreSQL.
1. Write a query that returns each category and the corresponding total revenue for that
category for the sale_year 2016. The output should be arranged alphabetically.
2. Write a query that returns a list of sub_categories and their corresponding average
unit_price, average unit_cost, as well as the difference between these two values
(name this column margin) for the sale_year 2015. Organize the results alphabetically.
3. Write a query that returns the total number of female buyers (gender) who made
purchases in the Clothing category.
4. Write a query that returns the age, sub_cateogry, average quantity (as a whole
number), and average cost of products purchased by each age and sub_category.
Output should show the columns in the same order they are listed. Organize the data by
age, oldest to youngest, and then by sub_category alphabetically.
5. Write a query that returns a list of countries where more than 30 transactions were
made by customers between the ages of 18-25(inclusive).
6. Write a query that returns a list of sub_categories along with their average quantity
and average cost, both rounded to 2 decimal places, and named as avg_quantity and
avg_cost respectively. Only include sub_categories that have at least 10 records in the
data set. Organize the data by sub_category alphabetically.
7. Write a query that returns each sub_cateogry and their respective total quantity and
total revenue for male buyers (gender), in the sale_year of 2016.
8. Write a query to determine each countrys total revenue generated from sales, sorted
alphabetically.
9. Write a query to determine the highest unit_cost, lowest unit_cost, and average
unit_cost for each gender in each category. The output columns should be gender,
category, high_cost, low_cost, avg_cost. Organize the results by gender and then
category.
10. Write a query to return the country that has the highest average revenue. Your output
columns should be country and high_sales.
Hint: To obtain the highest value, you will need to return only one row from your results. Think of
how youll need to sort the output and then see this link if you need guidance on how to select a
single row.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions