BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TOP and Group By

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Marcello Dias
Guest





PostPosted: Mon May 10, 2004 1:39 pm    Post subject: TOP and Group By Reply with quote



Giving the folowing table

COD_ALT_CLIENTE INTEGER
VALOR_SORTEIO NUMERIC 13,2
DT_SORTEIO SMALLDATETTIME

How can i know the top 4 dates of every COD_ALT_CLIENTE
That are between ‘05/05/2004’ and ‘12/12/2004’

I mean a resultset like this

COD_ALT_CLIENTE VALOR_SORTEIO DT_SORTEIO
1 500,00 06/05/2004
1 500,00 14/05/2005
1 500,00 19/05/2004
1 500,00 29/05/2004
7 500,00 05/05/2004
7 500,00 12/05/2004
7 500,00 14/05/2004
7 500,00 16/05/2004

Back to top
Robert MacLean
Guest





PostPosted: Mon May 10, 2004 2:02 pm    Post subject: Re: TOP and Group By Reply with quote



Marcello Dias <md9@ikillincaseofspam (AT) ibest (DOT) com.br> wrote:
Quote:
Giving the folowing table

How can i know the top 4 dates of every COD_ALT_CLIENTE

In MS-SQL
SELECT TOP 4 x FROM table WHERE (COD_ALT_CLIENTE > '05/05/2004') AND
(COD_ALT_CLIENTE < '12/12/2004')

In MySQL
SELECT x FROM table WHERE (COD_ALT_CLIENTE > '05/05/2004') AND (COD_ALT_CLIENTE
< '12/12/2004') LIMIT 5

Your could add ORDER BY COD_ALT_CLIENTE (ASC|DESC) to have it order a specific
way, in either DB
--
Robert MacLean
http://www.sadev.co.za



Back to top
Marcello Dias
Guest





PostPosted: Mon May 10, 2004 2:23 pm    Post subject: Re: TOP and Group By Reply with quote





Quote:
How can i know the top 4 dates of every COD_ALT_CLIENTE

In MS-SQL
SELECT TOP 4 x FROM table WHERE (COD_ALT_CLIENTE > '05/05/2004') AND
(COD_ALT_CLIENTE < '12/12/2004')

In MySQL
SELECT x FROM table WHERE (COD_ALT_CLIENTE > '05/05/2004') AND (COD_ALT_CLIENTE
'12/12/2004') LIMIT 5

Your could add ORDER BY COD_ALT_CLIENTE (ASC|DESC) to have it order a specific
way, in either DB
--
Hi Robert,


I think you didnīt understood the question
COD_ALT_CLIENTE is the ID not a Date.


Marcello

Back to top
Robert MacLean
Guest





PostPosted: Mon May 10, 2004 2:25 pm    Post subject: Re: TOP and Group By Reply with quote

Marcello Dias <md9 (AT) blablaibest (DOT) com.br> wrote:
Quote:
I think you didnīt understood the question

Sorry Wink
Just change the field names as need


--
Robert MacLean
http://www.sadev.co.za



Back to top
Marcello Dias
Guest





PostPosted: Mon May 10, 2004 2:32 pm    Post subject: Re: TOP and Group By Reply with quote


Robert,

See the result set I want In my first message.
The problem is that i cant have the 4 dates for every group.

In fact i need them in order to join them with aother table,
I almost convinced to use a cursor for ths case.

Marcello

"Robert MacLean" <robert (AT) nospam (DOT) sadev.co.za> wrote:
Quote:
Marcello Dias <md9 (AT) blablaibest (DOT) com.br> wrote:
I think you didnīt understood the question

Sorry Wink
Just change the field names as need


--
Robert MacLean
http://www.sadev.co.za




Back to top
Wayne Niddery [TeamB]
Guest





PostPosted: Mon May 10, 2004 8:42 pm    Post subject: Re: TOP and Group By Reply with quote

Marcello Dias wrote:
Quote:
Giving the folowing table

COD_ALT_CLIENTE INTEGER
VALOR_SORTEIO NUMERIC 13,2
DT_SORTEIO SMALLDATETTIME

How can i know the top 4 dates of every COD_ALT_CLIENTE
That are between '05/05/2004' and '12/12/2004'

I think you would have a much easier time writing a stored procedure for
this rather than trying to figure out a single select statement.

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"True peace is not the absence of tension, but the presence of
justice." - Martin Luther King, Jr.



Back to top
Macello Dias
Guest





PostPosted: Mon May 10, 2004 11:54 pm    Post subject: Re: TOP and Group By Reply with quote


"Wayne Niddery [TeamB]" <wniddery (AT) chaffaci (DOT) on.ca> wrote:

Quote:
I think you would have a much easier time writing a stored procedure for
this rather than trying to figure out a single select statement.
Thank you.I'm already doing this.


Marcello


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.