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.
| Author |
Topic |
|
nitinnjp
Starting Member
6 Posts |
Posted - 2009-09-22 : 03:01:36
|
| I have 3 tables which has following structures.1.Tracking_productdetail proudctId userid datetime type2.pc_products productId(pk) companyId3.compant_master companyId(pk) companyNameExpected output:productId,userId,datetime(input date Jan 2009),type,companyNamei tried thisSELECT min(cm.companyName) CompanyName,min(CONVERT(CHAR(4), datetime, 100) + CONVERT(CHAR(4), datetime, 120)) MonthYear,min(Type) Type, count(*) AS FileCount FROM Tracking_productdetail tp,company_master cm,pc_products pcWHERE datetime between '8/1/2009' AND '8/31/2009' and pc.productId=tp.productId and pc.companyId=cm.companyId GROUP BY Type this gives proper output but i am not able to take a companyId which is of integer datatype in above case companyname and datetime does not affect by min() function. if i use companyId it gives an error "select list because it is not contained in either an aggregate function or the GROUP BY clause."plz give me solution as early as possible thanks in advancenitin patil |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-24 : 02:25:08
|
| SELECT companyid,min(cm.companyName) CompanyName,min(CONVERT(CHAR(4), datetime, 100) + CONVERT(CHAR(4), datetime, 120)) MonthYear,min(Type) Type, count(*) AS FileCount FROM Tracking_productdetail tp,company_master cm,pc_products pcWHERE datetime between '8/1/2009' AND '8/31/2009' and pc.productId=tp.productId and pc.companyId=cm.companyId GROUP BY Type,companyidMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|