Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Storing and calculating sales per item

$
0
0

The case: We have a item, on that item we have a fee. If the item has sold more than 1000 copies, the fee will drop. Therefor i need to have a place that calculates/stores total sales per item. This can then be used to set the fee when i run my stored procedure for sales etc. 

Database explained shortly: 

The sales database looks like this: 
ItemID, SalesDate, Quantity, Name.
Example: 

1399, 2014-01-01, 2, Fompa.
1081, 2014-01-01, 13, Asddd. 
1399, 2014-01-03, 1, Fompa. 
Etc. 

The item database looks like this: 
ItemID, Name, Author, etc

Now my boss asked me if i maybe should add total sales to the item database, but how is that possible? 

I have also tried to gather all items and show the total sales, but something goes wrong, the itemID are not grouping together..

here is the query: select ItemID, QUANTITY from BOOK_SALES group by ItemID, QUANTITY order by MAX(quantity) DESC

If i get this query right, is it possible to store the query within a database table? 



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>