78.2k views
2 votes
Create a query based on qryq1salesvolumebytype and qrytotalq1salesvolume that calculates the percentage of quarter 1 sales volume for each producttype. Your subquery should include the producttype field and a calculated field named %ofq1salesvolumebytype that divides q1salesvolumebytype by totalq1salesvolume.

a) SELECT producttype, q1salesvolumebytype / totalq1salesvolume AS %ofq1salesvolumebytype FROM qryq1salesvolumebytype
b) SELECT producttype, q1salesvolumebytype % totalq1salesvolume AS %ofq1salesvolumebytype FROM qrytotalq1salesvolume
c) SELECT producttype, q1salesvolumebytype / SUM(totalq1salesvolume) AS %ofq1salesvolumebytype FROM qrytotalq1salesvolume
d) SELECT producttype, q1salesvolumebytype * totalq1salesvolume AS %ofq1salesvolumebytype FROM qryq1salesvolumebytype

User Zerocog
by
8.0k points

1 Answer

5 votes

Final answer:

To calculate the % of Q1 sales volume by product type, divide q1salesvolumebytype by the sum of totalq1salesvolume from the qrytotalq1salesvolume in a subquery, and select producttype along with this calculated field.

Step-by-step explanation:

The query for calculating the percentage of Quarter 1 sales volume for each product type based on the two mentioned queries (qryq1salesvolumebytype and qrytotalq1salesvolume) involves joining this data and then performing a calculation. In SQL, you typically use a division operation to calculate percentages. Here's the correct SQL query format:

SELECT producttype, q1salesvolumebytype / (SELECT SUM(totalq1salesvolume) FROM qrytotalq1salesvolume) AS %ofq1salesvolumebytype FROM qryq1salesvolumebytype

This query divides the Q1 sales volume for each product type by the total Q1 sales volume from another query, giving us the percentage of Q1 sales volume by product type.

User Pandy Legend
by
7.7k points