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 |
|
bjornh
Yak Posting Veteran
87 Posts |
Posted - 2002-04-13 : 06:01:42
|
| Hi, I have a table that looks like this:aol_teller---------------datum smalldatetimebezoekers intand wrote this query:SELECT maand = datepart(month, datum), bezoekers = sum(convert(float, bezoekers)) FROM aol_teller GROUP BY datepart(month, datum)But now I want to select the month with the most visitors (bezoekers, it's dutch ;))I've tryed something with max() function, but it just can't get it right. Can somebody help me with it? thanks.Bjorn Huijbregts |
|
|
LarsG
Constraint Violating Yak Guru
284 Posts |
Posted - 2002-04-13 : 07:45:43
|
| SELECT top 1 maand = datepart(month, datum), bezoekers = sum(convert(float, bezoekers)) FROM aol_teller GROUP BY datepart(month, datum) order by bezoekers desc |
 |
|
|
bjornh
Yak Posting Veteran
87 Posts |
Posted - 2002-04-13 : 08:10:57
|
| aah thanks, it works. |
 |
|
|
LarsG
Constraint Violating Yak Guru
284 Posts |
Posted - 2002-04-13 : 08:15:50
|
| I just wondered if you wish to take separate years into account?SELECT top 1 aar = datepart(year,datum), maand = datepart(month, datum), bezoekers = sum(convert(float, bezoekers)) FROM aol_teller GROUP BY datepart(year,datum),datepart(month, datum) order by bezoekers desc |
 |
|
|
|
|
|
|
|