Answered step by step
Verified Expert Solution
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 : Creating a table using the following attributes: saledate,saleyear,salemonth,age,gender,country,state,category,subcategory,quantity,unitcostunitprice,cost,revenue: Please use the following instructions: PART Creating the Table and Importing the Data
Create the table with appropriate data types
a Name the table customerspending
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 : 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.
Write a query that returns each category and the corresponding total revenue for that
category for the saleyear The output should be arranged alphabetically.
Write a query that returns a list of subcategories and their corresponding average
unitprice, average unitcost as well as the difference between these two values
name this column margin for the saleyear Organize the results alphabetically.
Write a query that returns the total number of female buyers gender who made
purchases in the Clothing category.
Write a query that returns the age, subcateogry, average quantity as a whole
number and average cost of products purchased by each age and subcategory.
Output should show the columns in the same order they are listed. Organize the data by
age, oldest to youngest, and then by subcategory alphabetically.
Write a query that returns a list of countries where more than transactions were
made by customers between the ages of inclusive
Write a query that returns a list of subcategories along with their average quantity
and average cost, both rounded to decimal places, and named as avgquantity and
avgcost respectively. Only include subcategories that have at least records in the
data set. Organize the data by subcategory alphabetically.
Write a query that returns each subcateogry and their respective total quantity and
total revenue for male buyers gender in the saleyear of
Write a query to determine each countrys total revenue generated from sales, sorted
alphabetically.
Write a query to determine the highest unitcost lowest unitcost and average
unitcost for each gender in each category. The output columns should be gender,
category, highcost lowcost avgcost Organize the results by gender and then
category.
Write a query to return the country that has the highest average revenue. Your output
columns should be country and highsales.
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started