Using the TOP argument

G

Guest

Hello all,

I am using the TOP argument in a query (below). It works fine as long as I
type the line number in the Where clause. I have 5 lines and I would like to
get the TOP 15 for each of the 5 lines. Is there a way to do this within a
single query,?

Select TOP 15 line, msg, sum(datedif(“â€sâ€â€, stime, ctime) as Duration
From LinsState
Where line = Line 1
Group by line, msg
Order by line, sum(datedif(“â€sâ€â€,stime, ctime) desc


Thanks for looking.
 
G

Guest

Hi Mark
How can you tell which 15 records to choose from each line?

For the example let say that you want the top 15 by a DateField
Try

Select T1.line, T1.msg, sum(datedif("s", T1.stime, T1.ctime) as Duration
From LinsState As T1
Where DateField In (Select Top 15 DateField From LinsState As T2 Where
T2.line = T1.line Order By T2.DateField Desc)
Group by line, msg
Order by line, sum(datedif("s",stime, ctime) desc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Parameterizing in a Cross Tab Query 2
Parameter Error for Year 2010 7
Top 15 1
Top 3 3
Top 3 per group 3
Strange result from query, '>' gives same result as '>=' 6
Top 25 brokers query help 1
Top 5 3

Top