Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 12th, 2006, 05:55 AM
Authorized User
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default (Resolved) Select top10 problems

I have the following data structure

Date name value
1-jan-2006 abc 200
1-jan-2006 bcd 400
31-mar-2006 abc 700

so I will have lots of data for each day, what I need to do is find the the min and max sum(top 10 value per day) .. It is fairly trivial to get the top 10, but I am struggeling with how to get this data on a per day basis. I am using SQL.

I was thinking that I would need to loop through the data and create a temp table containing the sum of top ten values on a daily basis, then requery this table to find the min and max.

can anyone suggest the best way to do this. can it be done in one select statement?
Reply With Quote
  #2 (permalink)  
Old April 12th, 2006, 09:34 AM
Authorized User
Join Date: Mar 2006
Location: London, , United Kingdom.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts

Problem Sorted.. I thought I would post my result here

    MAX(MyVal_Sum) 'Max Top 10', 
    MIN(MyVal_Sum) 'Min Top 10' 

    (SELECT SUM(d.MyVal) MyVal_Sum,d.MyDate 
    FROM MyTable d 
    WHERE MyIdent in (SELECT TOP 10 c.MyIdent 
                    MyTable c 
                WHERE c.MyDate= d.MyDate 
                ORDER BYc.MyVal desc) 

    GROUP BY d.MyDate) temptable

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Resolved] Combine select from different platforms snufse SQL Server 2005 5 November 14th, 2008 06:08 AM
Having Problems with my Insert Command - RESOLVED Andrew.Berry ASP.NET 2.0 Basics 1 October 2nd, 2007 09:59 AM
Problems with Select & Where statement sharon5469 ASP.NET 1.0 and 1.1 Basics 3 June 11th, 2007 07:09 PM
SELECT Problems Thpuffer Classic ASP Databases 1 June 19th, 2006 05:06 PM
Problems with SELECT DISTINCT dparsons SQL Server 2000 2 April 2nd, 2006 03:55 PM

All times are GMT -4. The time now is 07:00 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.