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)
 Query

Author  Topic 

sam_sh
Starting Member

4 Posts

Posted - 2009-08-04 : 01:38:08
Hi,
I have 2 tables:

Table1:
ID Subject Date
--------------------
1 sub1 01/01/09
2 sub2 01/02/09
3 sub3 01/03/09

Table2:
IDTable1 User Number
----------------------
1 A 5
1 B 7
1 C 3
2 A 10
2 B 7
3 A 1
3 C 6

Output (between 2 dates '01/01/09' and '01/02/09):

ID Subject sum(number)
-------------------------
1 sub1 15
2 sub2 17

thanks



khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-08-04 : 02:20:13
[code]
select t1.ID, t1.Subject, sum(t2.Number)
from table1 t1
inner join table2 t2 on t1.ID = t2.ID
where t1.Date between '20090101' and '20090102'
group by t1.ID, t1.Subject
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

saran_d28
Starting Member

36 Posts

Posted - 2009-08-04 : 02:29:49
Hi try this,

select id, subject, sum(user_numer) from
(
SELECT a.id, a.subject, b.user_number
from table1 a
join table2 b
on a.id = b. id
and a.date1 between '01-jan-2009' and '02-jan-2009'
)main
group by id, subject

--Saravanan
Go to Top of Page

sam_sh
Starting Member

4 Posts

Posted - 2009-08-04 : 13:10:03
Thank you
Go to Top of Page
   

- Advertisement -