Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 22nd, 2004, 11:37 PM
mae123 mae123 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 11 mae123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sql Statement (select Top)

TableA:

Country CountItem CatDescription
-----------------------------------
Hong Kong 50 Gifts Premium
Hong Kong 2 Literature
Hong Kong 2 Advertisement
Hong Kong 1 Sports
Australia 8 Gifts Premium
Australia 5 Sports

I would like to query it to have result below.
How to query?
(Select only Top 3- based on CountItem DESC)

Country Top1 Top2 Top3
-----------------------------------------------------
Hong Kong Gifts Premium Literature Advertisement
Australia Gifts Premium Sports -nil-


Pls help.
Thanks

Reply With Quote
  #2  
Old July 23rd, 2004, 02:21 AM
Kris_Vanherck's Avatar
Kris_Vanherck Kris_Vanherck is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Belgium, Antwerp
Posts: 177 Kris_Vanherck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 sec
Reputation Power: 5
i don't think this can be done by an SQL statement, you'll need a function or stored procedure for thing (and not a small one)

Reply With Quote
  #3  
Old July 23rd, 2004, 02:56 AM
mae123 mae123 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 11 mae123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
select the records TOP2

But Is it possible If I select only one records of the TOP 2?

Reply With Quote
  #4  
Old July 23rd, 2004, 06:29 AM
Kris_Vanherck's Avatar
Kris_Vanherck Kris_Vanherck is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Belgium, Antwerp
Posts: 177 Kris_Vanherck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 sec
Reputation Power: 5
selecting the max, min or top is no problem

its the horizontal movement (the top 3 in 3 record) that is difficult

so things like this:
PHP Code:
 Country Top1 
-----------------------
Hong Kong Gifts Premium
Australia Gifts Premium 


are no problem, but things like this

PHP Code:
 Country Top1 Top2 Top3 
-----------------------------------------------------
Hong Kong Gifts Premium Literature Advertisement
Australia Gifts Premium Sports 
-nil


can give you migraines

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Sql Statement (select Top)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT