| View previous topic :: View next topic |
| Author |
Message |
Marcello Dias Guest
|
Posted: Mon May 10, 2004 1:39 pm Post subject: TOP and Group By |
|
|
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
|
Posted: Mon May 10, 2004 2:02 pm Post subject: Re: TOP and Group By |
|
|
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
|
Posted: Mon May 10, 2004 2:23 pm Post subject: Re: TOP and Group By |
|
|
| 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
|
Posted: Mon May 10, 2004 2:25 pm Post subject: Re: TOP and Group By |
|
|
Marcello Dias <md9 (AT) blablaibest (DOT) com.br> wrote:
| Quote: | I think you didnīt understood the question
|
Sorry
Just change the field names as need
--
Robert MacLean
http://www.sadev.co.za
|
|
| Back to top |
|
 |
Marcello Dias Guest
|
Posted: Mon May 10, 2004 2:32 pm Post subject: Re: TOP and Group By |
|
|
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
Just change the field names as need
--
Robert MacLean
http://www.sadev.co.za
|
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Mon May 10, 2004 8:42 pm Post subject: Re: TOP and Group By |
|
|
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
|
Posted: Mon May 10, 2004 11:54 pm Post subject: Re: TOP and Group By |
|
|
"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 |
|
 |
|