Search This Blog

Monday, February 11, 2013

IN key in sql server query


*****************************************************************************
Ues (in) key for sql query::

select * from formA1

sno
User
id
User
type
year
month
fileno
addno
Computer
no
person
zoneid
regionid
1
1
1
2012     
9
234
345
3
4
1
2
2
3
1
2012     
9
2
4
5
56
1
3
3
1
1
2012     
9
3
3
3
3
1
4
4
4
1
2012     
9
2
3
34
3
1
0
7
3
1
2012     
8
45
3
45
45
1
6
6
3
3
2012     
8
34
34
56
555
2
5


select regionid from formA1 where zoneid=1 and year='2012' and month='9' and usertype='1'

regionid
2
3
4
0

elect SUM(computerno) as totalcomputerno,SUM(fileno) as totalfileno,SUM(person)as totalperson from formA1 where year='2012' and month='9' and usertype='1' and regionid in(select regionid from formA1 where zoneid=1)

totalcomputerno
totalfileno
totalperson
45
241
66

 

No comments :