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
 General SQL Server Forums
 New to SQL Server Programming
 select problem

Author  Topic 

sangoku
Starting Member

19 Posts

Posted - 2009-09-05 : 07:25:44
Hy i have again a BIG problem, i am on the verge of failing i have the folowing querry:


SELECT MONTH(Rodjendan) AS MjesecRodjenja, count(month(Rodjendan)) as BrojRodjendana FROM Korisnik
GROUP BY MONTH(Rodjendan)
ORDER BY MONTH(Rodjendan) DESC


and i get

MjesecRodjenja BrojRodjendana
7 2
5 2
3 1
2 1

how can i only show the results with only maximall "BrojRodjendana" is shown


PLEASE HELP me out im stuck on a test....

while earth still spining
live on, have fun
else
move to mars

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-05 : 08:25:25
select top 1 with ties * from
(
SELECT MONTH(Rodjendan) AS MjesecRodjenja, count(month(Rodjendan)) as BrojRodjendana FROM Korisnik
GROUP BY MONTH(Rodjendan)
) as t
ORDER BY BrojRodjendana DESC

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sangoku
Starting Member

19 Posts

Posted - 2009-09-05 : 08:45:06
I already solcved it XD sorry to bother you it was like:
USE WebForum
Go
DECLARE @tableTem table (MjesecRodjenja int, BrojRodjenja int)
DECLARE @MaxVrednost int

INSERT @tableTem

SELECT MONTH(Rodjendan), count(month(Rodjendan)) FROM Korisnik
GROUP BY MONTH(Rodjendan)


SELECT @MaxVrednost = (SELECT MAX(BrojRodjenja) FROM @tableTem)


SELECT * FROM @tableTem
WHERE BrojRodjenja = @MaxVrednost

and i solved it XD

while earth still spining
live on, have fun
else
move to mars
Go to Top of Page
   

- Advertisement -