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)
 Help with select and top

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2009-03-04 : 12:57:25
Hi,
I have a table that contains the following fields:
app_id int
sujbect_id int
issue_id int
date_reported datetime
agent_id int

I have a query such as the following:
Select app_id, subject_id,issue_id from
tbl_issuesReported
where date_reported between @date1 and @date2

However, i need to change the query and show the 10 most issues that were reported
between the dates selected.

Any help will be appreciated.

Thanks

Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-04 : 13:09:25
[code]
Select top 10 with ties app_id, subject_id,issue_id from
tbl_issuesReported
where date_reported between @date1 and @date2
group by app_id, subject_id,issue_id
order by count(*) desc
[/code]
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-04 : 13:10:06
Perhaps this:

Select TOP 10 app_id, subject_id,issue_id from
tbl_issuesReported
where date_reported between @date1 and @date2
ORDER BY date_reported



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

subhash chandra
Starting Member

40 Posts

Posted - 2009-03-04 : 17:21:14
You are asking to most issues that were reported between given two dates but missed what most?
If mst recent then Tara's query with a little bit change
ORDER BY date_reported DESC
Go to Top of Page

malawneh
Starting Member

24 Posts

Posted - 2009-03-04 : 18:37:55

SELECT TOP 10 app_id
, subject_id
, issue_id
FROM tbl_issuesReported
WHERE date_reported BETWEEN @Date1 AND @Date2
GROUP BY app_id
, subject_id
, issue_id
ORDER BY COUNT(issue_id) DESC

Michael Alawneh, DBA
Go to Top of Page
   

- Advertisement -