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 |
|
samsun125
Yak Posting Veteran
63 Posts |
Posted - 2009-06-19 : 12:32:06
|
| Hi all,I have one query i have 3 tables1.statemaster2.countrymaster3.tbl_salesin statemaster columns are stateid,statename,countryidin countrymaster columns are countryid,countrynamein tbl_sales columns are date,stateid,sales.but the output result is :count(sales),countryname where date is between getdate()-7 and getdate()-1 -----(means past 7 days)data how to write query for this.if anybody knows please help meRegardsRama |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-19 : 13:06:31
|
| [code]SELECT c.countryname,COUNT(sales)FROM countrymaster cJOIN statemaster sON s.countryid=c.countryidJOIN tbl_sales tsON ts.stateid=s.stateidWHERE ts.date > = DATEADD(dd,DATEDIFF(dd,0,getdate())-7,0)AND ts.date <=DATEADD(dd,DATEDIFF(dd,0,getdate())-1,0)GROUP BY c.countryname[/code] |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-06-19 : 13:13:26
|
| SELECT count(sales) -- Do you mean sum(sales)? ,cn.CountryNameFROM table_Sales sINNER JOIN statemaster smON s.stateid = sm.stateidINNER JOIN countrymaster cmON sm.countryid = cm.countryidWHERE s.Date >= DATEADD(day,datediff(day,8,getdate()),0) and s.Date < DATEADD(day,datediff(day,0,getdate()),0)GROUP BY cn.CountryNameJim |
 |
|
|
|
|
|
|
|