I have not worked with SQL very much and am way out of my admittedly shallow depth. I need to build a query to retrieve a data set for a VB program using a Stored Procedure, it must use data from two fields: a year to date sales field called ytd_sales and a field that lists book types called types. From these fields I need to create four fields three containing calculated data each record corresponding to a book type. The first field is the book type field which will just contain each type of book. The first calculated field will be the ytd for all books of a specific type, the second is the average ytd of a book of that type, and the last is just a count of the number books in that type. I am including my code as it stands right now but it is doing nothing close to what I want. I would greatly appreciate any help or suggestions you might offer.
-Keith
CODE
ALTER PROCEDURE YTDSalesByBookType
AS
SELECT SUM(ytd_sales), ytd_sales/COUNT(type) AS Average_Sales, type, COUNT(type) AS BooksSold
FROM titles
GROUP BY type, ytd_sales WITH ROLLUP
RETURN