| Author |
Topic |
|
blindmancries
Starting Member
3 Posts |
Posted - 2006-01-30 : 07:06:55
|
| I need some help regarding SQL Query.I have a SQL Server databse a big one with a lot of records with table in like: EMBG Name Surname Total date1. 2712 Naim Arifi 70 2/23/20052. 2563 xxx yyyy 85 5/9/20053. 2492 aaa bbb 563 7/17/20054. 2712 Naim Arifi 79 12/25/20055. 2712 Naim Arifi 123 1/10/2006I need a query who will count how many times for example Naim Arifi is like a record for a period of time. Let say I want to find from January 1-st 2005 till today. Another one is that I need to SUM the total for one person. for example Naim Arifi With total 272. Because the db is big one, it should look like this:First case:1. 2712 Naim Arifi 32. 2563 xxx yyyy 13. 2492 aaa bbb 1 And, Second case:1. 2712 Naim Arifi 2722. 2563 xxx yyyy 1853. 2492 aaa bbbb 322......12564. vvv vvv 782I really will apprepriate this if someone will help me regarding this problem.Thanks in advice,N.A |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-01-30 : 07:45:07
|
Use Group Byselect Name, Surname, count(*) from yourtablegroup by Name, Surnameselect Name, Surname, sum(Total)from yourtablegroup by Name, Surname ----------------------------------'KH' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
blindmancries
Starting Member
3 Posts |
Posted - 2006-01-30 : 09:25:03
|
| Yeah it is OK. Query works. I have made like this select Name, Surname, sum(total)"totali", count(*)"nr" from tblgroup by Name, SurnameHow can I sort them starting from the biggest one. In Descending form. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-30 : 09:34:25
|
| Select * from(select Name, Surname, sum(total)"totali", count(*)"nr" from tblgroup by Name, Surname) Torder by nr DESCMadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-01-30 : 09:45:47
|
Looks like a long distance relative ----------------------------------'KH' |
 |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2006-01-30 : 10:39:03
|
| I'm the happy blindman. Can't you tell the difference? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|