Go Back   Rhinocerus > Newsgroup > Newsgroup comp.databases.* > Newsgroup comp.databases.ms-sqlserver

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-08-2005, 01:42 PM
PYCTAM
Guest
 
Posts: n/a
Default grouping select query

Hi,

I have data stored as in below sample :

-------------------------------+---------------------------------+--------------
DateBegin | DateEnd | Rate
-------------------------------+---------------------------------+--------------
2005-11-13 00:00:00 2005-11-14 00:00:00 63.0000
2005-11-14 00:00:00 2005-11-15 00:00:00 63.0000
2005-11-15 00:00:00 2005-11-16 00:00:00 45.0000
2005-11-16 00:00:00 2005-11-17 00:00:00 45.0000
2005-11-17 00:00:00 2005-11-18 00:00:00 45.0000
2005-11-18 00:00:00 2005-11-19 00:00:00 45.0000
2005-11-19 00:00:00 2005-11-20 00:00:00 45.0000
2005-11-20 00:00:00 2005-11-21 00:00:00 63.0000
2005-11-21 00:00:00 2005-11-22 00:00:00 63.0000
-------------------------------+---------------------------------+--------------


I have to group the select query in this way :

-------------------------------+---------------------------------+--------------
DateBegin | DateEnd | Rate
-------------------------------+---------------------------------+--------------
2005-11-13 00:00:00 2005-11-15 00:00:00 63.0000
2005-11-15 00:00:00 2005-11-20 00:00:00 45.0000
2005-11-20 00:00:00 2005-11-22 00:00:00 63.0000
-------------------------------+---------------------------------+--------------

When I run below grouped statement, I get follewed result:

SELECT MIN(DateBegin) AS DateBegin, MAX(DateEnd) AS DateEnd,
Rate FROM X GROUP BY Rate

-------------------------------+---------------------------------+--------------
DateBegin | DateEnd | Rate
-------------------------------+---------------------------------+--------------
2005-11-13 00:00:00 2005-11-22 00:00:00 63.0000
2005-11-15 00:00:00 2005-11-20 00:00:00 45.0000
-------------------------------+---------------------------------+--------------

How can I do a query like in 2nd sample from top?

best regards,
rustam bogubaev

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 11-08-2005, 03:15 PM
Robert Klemme
Guest
 
Posts: n/a
Default Re: grouping select query

PYCTAM wrote:
> Hi,
>
> I have data stored as in below sample :
>
> -------------------------------+---------------------------------+------

--------
> DateBegin | DateEnd | Rate
> -------------------------------+---------------------------------+------

--------
> 2005-11-13 00:00:00 2005-11-14 00:00:00 63.0000
> 2005-11-14 00:00:00 2005-11-15 00:00:00 63.0000
> 2005-11-15 00:00:00 2005-11-16 00:00:00 45.0000
> 2005-11-16 00:00:00 2005-11-17 00:00:00 45.0000
> 2005-11-17 00:00:00 2005-11-18 00:00:00 45.0000
> 2005-11-18 00:00:00 2005-11-19 00:00:00 45.0000
> 2005-11-19 00:00:00 2005-11-20 00:00:00 45.0000
> 2005-11-20 00:00:00 2005-11-21 00:00:00 63.0000
> 2005-11-21 00:00:00 2005-11-22 00:00:00 63.0000
> -------------------------------+---------------------------------+------

--------
>
>
> I have to group the select query in this way :
>
> -------------------------------+---------------------------------+------

--------
> DateBegin | DateEnd | Rate
> -------------------------------+---------------------------------+------

--------
> 2005-11-13 00:00:00 2005-11-15 00:00:00 63.0000
> 2005-11-15 00:00:00 2005-11-20 00:00:00 45.0000
> 2005-11-20 00:00:00 2005-11-22 00:00:00 63.0000
> -------------------------------+---------------------------------+------

--------
>
> When I run below grouped statement, I get follewed result:
>
> SELECT MIN(DateBegin) AS DateBegin, MAX(DateEnd) AS DateEnd,
> Rate FROM X GROUP BY Rate
>
> -------------------------------+---------------------------------+------

--------
> DateBegin | DateEnd | Rate
> -------------------------------+---------------------------------+------

--------
> 2005-11-13 00:00:00 2005-11-22 00:00:00 63.0000
> 2005-11-15 00:00:00 2005-11-20 00:00:00 45.0000
> -------------------------------+---------------------------------+------

--------
>
> How can I do a query like in 2nd sample from top?


Care to explain by what you want to group? I cannot recognize it from
your sample output.

robert

Reply With Quote
  #3 (permalink)  
Old 11-08-2005, 09:36 PM
Hugo Kornelis
Guest
 
Posts: n/a
Default Re: grouping select query

On 8 Nov 2005 06:42:33 -0800, PYCTAM wrote:

(snip)

Hi rustam,

You posted an exact identical copy of this question in the group
microsoft.public.sqlserver.programming, and I posted a reply there.

Please do not post the same question independently to multiple groups.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Reply With Quote
 
Reply

Thread Tools
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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Tranpose : macro help Arthur Tabachneck Newsgroup comp.soft-sys.sas 0 02-22-2009 11:11 PM
Re: Help with Array for Healthcare Claims Analysis sas 9 bi user Newsgroup comp.soft-sys.sas 0 07-31-2008 05:44 PM



All times are GMT. The time now is 06:38 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.