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 2005 Forums
 Transact-SQL (2005)
 Group By on single column

Author  Topic 

pyu.agrawal
Starting Member

29 Posts

Posted - 2009-09-21 : 10:31:15
i have two table pc_products and Tracking_productdetail whose structure is as follow.
pc_products
productid(pk)
companyId

where as Tracking_productdetail as contain the following column.

product_id
userId
datetime1
type

output needed
companyid, month & year(coming from Tracking_productdetail.datetime1), count of type.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-21 : 10:58:49
[code]
select p.companyid
,year( dateadd(month, datediff(month, 0, t.datetime1), 0)) as [year]
,month(dateadd(month, datediff(month, 0, t.datetime1), 0)) as [month]
,count(t.type) as typecount
from pc_products p
inner join tracking_productdetail t
on t.productid = p.productid
group by p.companyid
,dateadd(month, datediff(month, 0, t.datetime1), 0)
[/code]

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -