Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Top & Count?

Status
Not open for further replies.

NEveritt

MIS
Dec 30, 2002
25
GB
I am looking to do the following using SQL 2000.

I have a Brands field and a Reason field.

Each row has one brand and one reason.

I want to find the Top 3 for each brand. I have tried a count, with a top before it, and group by, but it only delivered the top 3 across all brands.

Any clues?

Hope this makes sense.

N
 
Well, your question is somewhat unclear so this query holds a lot of assumptions

Code:
select * t as ct
where reason in 
  (select top 3 reason from t
    where brand = ct.brand 
     order by reasonDate desc)

It is usually better to give a table description, some sample data and the expected result.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top