RE: Percentage of Total Sales by Department?
If you know how to convert this to qrp report, here is the sql for you.
SELECT tbl.Name department ,
tbl.AmtSold ,
tbl.AmtSold / SUM(tbl.AmtSold) OVER ( ) AS Percentage
FROM ( SELECT dbo.Department.Name ,
SUM(TE.Quantity * te.Price) AmtSold
FROM ( SELECT StoreID ,
TransactionNumber ,
CAST(time AS DATE) datesold
FROM dbo.[Transaction] WITH ( NOLOCK )
) t
LEFT JOIN ( SELECT StoreID ,
TransactionNumber ,
ItemID ,
Quantity ,
Price
FROM dbo.TransactionEntry WITH ( NOLOCK )
) te ON te.StoreID = t.StoreID
AND te.TransactionNumber = t.TransactionNumber
LEFT JOIN ( SELECT ID ,
DepartmentID
FROM dbo.Item WITH ( NOLOCK )
) item ON item.ID = TE.ItemID
LEFT JOIN dbo.Department WITH ( NOLOCK ) ON dbo.Department.ID = item.DepartmentID
LEFT JOIN ( SELECT id ,
storecode
FROM dbo.Store WITH ( NOLOCK )
) store ON store.ID = T.StoreID
WHERE t.datesold >= '2016-01-01'
GROUP BY dbo.Department.Name
) tbl
ORDER BY tbl.AmtSold DESC