Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.
-
Dave #1
Eliminating duplicates
Hi,
I have a view with the following columns:
member_rating_id
,rating_table_id
,member_id
,screen_name
,rating_value
,number_won
,number_drawn
,number_lost
,points_for
,points_against
,rating_date
,iso_country_code
I need to build a resultset of the top 20 ratings (based on rating_value),
with only one entry for each country, i.e. if there are 5 members from the
USA, I only want to see the one with the highest rating value in the
results.
The following SQL works, but isn't particularly fast:
select top 20
member_rating_id
,rating_table_id
,member_id
,screen_name
,rating_value
,number_won
,number_drawn
,number_lost
,points_for
,points_against
,rating_date
,iso_country_code
from
dbo.vw_member_rating_stats as mrs1
where
member_rating_id = (select top 1
member_rating_id
from
dbo.vw_member_rating_stats as mrs2
where
rating_table_id = @rating_table_id
and
mrs2.iso_country_code =
mrs1.iso_country_code
order by
rating_value desc)
order by
rating_value desc
If anyone can think of a better way of doing this, I'd love to hear it!!
TIA.
Dave
Dave Guest
-
Eliminating Doubles in SQL
I am developing a ecommerce website. In dreamweaver I have the product categories from the database display as links, my problem is that there is... -
eliminating red eye
I downloaded my pictures to iphoto and eliminated the "red eye" in some of the pictures. When I open them in photoshop the red eye is still present.... -
Eliminating dupe votes
Wonder if this is possible and if so anyone could give me a bit of a hand. I am writing a voting system which uses cookies to prevent multiple... -
eliminating moire patterns
How can you get rid of moire patterns from photo images in Photoshop Elements? I am running PSE in Windows 98. I am preparing digital photos of a... -
Eliminating the border area
are you talking about the html page? you can set the following: <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> Peter ... -
Bob Barrows #2
Re: Eliminating duplicates
Please provide sample data and show us (ion tabular form) the results you
want to return from the sample data.
Bob Barrows
Dave wrote:> Hi,
>
> I have a view with the following columns:
> member_rating_id
> ,rating_table_id
> ,member_id
> ,screen_name
> ,rating_value
> ,number_won
> ,number_drawn
> ,number_lost
> ,points_for
> ,points_against
> ,rating_date
> ,iso_country_code
>
> I need to build a resultset of the top 20 ratings (based on
> rating_value), with only one entry for each country, i.e. if there
> are 5 members from the USA, I only want to see the one with the
> highest rating value in the results.
>
> The following SQL works, but isn't particularly fast:
>
> select top 20
> member_rating_id
> ,rating_table_id
> ,member_id
> ,screen_name
> ,rating_value
> ,number_won
> ,number_drawn
> ,number_lost
> ,points_for
> ,points_against
> ,rating_date
> ,iso_country_code
> from
> dbo.vw_member_rating_stats as mrs1
> where
> member_rating_id = (select top 1
> member_rating_id
> from
> dbo.vw_member_rating_stats
> as mrs2 where
> rating_table_id =
> @rating_table_id and
> mrs2.iso_country_code =
> mrs1.iso_country_code
> order by
> rating_value desc)
> order by
> rating_value desc
>
> If anyone can think of a better way of doing this, I'd love to hear
> it!!
>
> TIA.
>
> Dave
Bob Barrows Guest



Reply With Quote

