Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Query to find out percentage - No Result

Author  Topic 

PeeJay2583
Starting Member

40 Posts

Posted - 2014-11-19 : 09:39:18
I have 2 tables where Table1 having fields OrderID, CustomerID, Date, ProductID and Table2 having fields ProductID, ProductCategory.
I want to find out what percentage was ordered in the last 3 months for ProductCategory = "ABC"

Query I am using is below -

SELECT Count(T1.[OrderID]) AS [CountOfOrder ID]
FROM Table1 AS T1 INNER JOIN Table2 AS T2 ON T1.[ProductID] = T2.[ProductID]
WHERE (((T2.[ProductCategory])="Book") AND ((T1.Date)>="10/01/2014"))
Group by T2.[ProductCategory]
/
(Select Count(T1.[Order ID])
FROM
Table1 T1 INNER JOIN Table2 T2 ON T1.[Product ID] =T2.[Product ID]
where T2.[ProductCategory] = "Book"
Group by T2.[ProductCategory])


I am not sure if I am using right subquery
   

- Advertisement -