Struggling with SQL Query for displaying 3 fields of data using only one
integer data entry
Im currently stuck on a project set for me using SQL and Php. I have two
seperate .csv tables with automated data that CAN be added to via another
webpage. This is not static data, it is dynamic and changeable.
Here is my objective:
Write a web page showing a table of sales (Volume and Price) of each
product for a single year. The user must be able to select the year.
So far with my query I've got this far:
SELECT Products.Name, SUM(MonthlySales.SalesVolume) as 'Total Sales'
FROM Products
INNER JOIN MonthlySales
ON Products.Id=MonthlySales.Id
GROUP BY Products.Name;
On top of that I need to be able to pass in a value (year) with php (which
i am capable of doing) to further narrow the search. Am i going the right
way with this? I have been struggling with this task for a while now.
Example Data:
MonthlySales.csv
Id ProductCode Month Year SalesVolume
23041 121 1 1980 983
23042 121 2 1980 960
23043 121 3 1980 939
23044 121 4 1980 927
23045 121 5 1980 931
23046 121 6 1980 950
23047 121 7 1980 975
Products.csv
Id,Name,Price
121,Jelly beans,6.79
122,Banana milkshake powder,8.31
123,Edam Cheese,18.73
124,Hairnet,8.05
125,Aubergine jam,2.66
By the end I need something like this displayed:
You selected Year: 1980
Name Price Volume
Jelly Beans 6.79 11000
Banana milkshake powder 8.31 15000
Any help would be much appreciated.
No comments:
Post a Comment