Re: Help with queries - Top N by Group, and Query using 'IN'
- From: Jason Lepack <jlepack@xxxxxxxxx>
- Date: Mon, 13 Aug 2007 14:29:38 -0700
For query 2 please supply sample data as well as expected output.
Here is a guess:
SELECT
sd.[server],
sd.[date],
sd.[data]
FROM
tbl_server_data sd
INNER JOIN (
SELECT
[server],
max(date) dt
FROM
tbl_server_data_old
GROUP BY
[server]) so
ON so.[server] = sd.[server]
AND so.[dt] = sd.[date]
On Aug 13, 4:15 pm, Benjamin <benjamin.dizenho...@xxxxxxxxx> wrote:
Thank you very much for the quick reply.
We are using SQL Server 2005 (to the best of my knowledge), and will
test your solution to query type 1.
As for your answer to query type 2, I guess my sample query wasn't
very informative. We need to use the 'IN' clause due to the subquery
actually makes use of the MAX function. I probably should have
included it. A better sample query would be:
select server, date, data ....
from tbl_server_data inner join other_tables_to_join....
where (server, date) IN
(select server, max(date) as date from
tbl_server_data_old group by server)
Again, thanks for any and all help
.
- References:
- Help with queries - Top N by Group, and Query using 'IN'
- From: Benjamin
- Re: Help with queries - Top N by Group, and Query using 'IN'
- From: Jason Lepack
- Re: Help with queries - Top N by Group, and Query using 'IN'
- From: Benjamin
- Help with queries - Top N by Group, and Query using 'IN'
- Prev by Date: Re: Help with queries - Top N by Group, and Query using 'IN'
- Next by Date: Re: Help with queries - Top N by Group, and Query using 'IN'
- Previous by thread: Re: Help with queries - Top N by Group, and Query using 'IN'
- Next by thread: Re: Help with queries - Top N by Group, and Query using 'IN'
- Index(es):
Relevant Pages
|