Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

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 Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old September 1st, 2004, 05:15 AM
joyce joyce is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 92 joyce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 18 sec
Reputation Power: 7
get rid of a field in group by

I need to sort my record by adult_rate, from cheapest to expensive.

this is my sql:
Quote:
select ratecodeno||ratetypeno, cvm_dip_id, database, productcode, productno, ratecodeno, ratetypeno, src_code, srt_code, operator_com_code, adult_rate, max(currencycode), min(base_discount_adult_rate), max(child_rate), min(base_discount_infant_rate), prp_rnt_id, cvm_id from twn_rate r1 where rownum<1000000 and suppliercode != 'TWN' and (prd_dip_id=0 or prd_dip_id in (70154, 70157, 70155, 70156, 70159, 70174, 70211, 70212, 70268, 70213, 70215, 70216, 70217, 70229, 70281, 70267, 70272, 70153)) and src_code in ('B','H','L','M','N','Q','T','V','X','S','W','Y') and srt_code like '%RETURN' and productno in (select productno from twn_product_location l where location_type='Origin' and townno = 42 and l.database = r1.database) and productno in (select productno from twn_product_location l where location_type='Destination' and townno = 460 and l.database = r1.database) and ('15-SEP-2004' <= todate and '22-SEP-2004' >= fromdate) and (!
cvm_rtc_id = 0 or cvm_rtc_id in ( select rbp_rtc_id from twn_rate_basis_period rb where cvm_rtc_id = rbp_rtc_id and rb.database=r1.database and ('15-SEP-2004' <= rbp_to_date and '22-SEP-2004' >= rbp_from_date) )) group by adult_rate, database, productcode, productno, srt_code, cvm_dip_id, prp_rnt_id, cvm_id order by adult_rate asc


From the above sql, i got result like this:
Quote:
Flight No. Class Rates
123 M 800
123 M 1000
123 L 400

124 M 700
124 M 1200
124 L 600


From the result listing, u can see that Class is being grouped together, then only do the sorting of rates. But what i want is sort the rate first no matter what, this is the result i want:
Quote:
Flight No. Class Rates
123 L 400
124 L 600
124 M 700
123 M 800
123 M 1000
124 M 1200


the src_code is the class (m,L), i tried to get rid of the src_code in the group by, but when i take it out, it generate sql error. what can i do? pls advise.

Last edited by joyce : September 1st, 2004 at 05:18 AM.

Reply With Quote
  #2  
Old September 1st, 2004, 08:43 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
If I understand your question perfectly, ORDER BY clause in your query suppose to work. You are using the column name in ORDER BY clause, now try to use the column position of this particular column in OREDR BY clause

For example according to your query, you clause would be:

ORDER BY 11
/

But this is not guarnteed to be work. I am unable to run your query without table staructure and data.

Reply With Quote
  #3  
Old September 1st, 2004, 09:06 AM
gcisjxs0 gcisjxs0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 8 gcisjxs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The group by is going to superceed you order by. I would make it an inline view then put your order by on the outside.

Something like

SELECT col1, col2
FROM (SELECT X col1,
MAX(Y) col2
FROM TABLE
GROUP BY X)
ORDER BY col1

Reply With Quote
  #4  
Old September 2nd, 2004, 12:08 AM
joyce joyce is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 92 joyce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 18 sec
Reputation Power: 7
HI Shafique, i tried your method, result displayed is the same, it did not sort by rate.

gcisjxs0, i wanted to try ur method but i do not know how to separate my query...

Reply With Quote
  #5  
Old September 2nd, 2004, 06:02 AM
gcisjxs0 gcisjxs0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 8 gcisjxs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Based on the query you have in the thread it would be something like this:

SELECT
trcodetypeno,
cvm_dip_id,
DATABASE,
productcode,
productno,
ratecodeno,
ratetypeno,
src_code,
srt_code,
operator_com_code,
adult_rate,
maxcurcode,
minbsadltrt,
maxchildrate,
minbsdscinfrt,
prp_rnt_id,
cvm_id
FROM
( SELECT
ratecodeno||ratetypeno trcodetypeno,
cvm_dip_id,
DATABASE,
productcode,
productno,
ratecodeno,
ratetypeno,
src_code,
srt_code,
operator_com_code,
adult_rate,
MAX(currencycode) maxcurcode,
MIN(base_discount_adult_rate) minbsadltrt,
MAX(child_rate) maxchildrate,
MIN(base_discount_infant_rate) minbsdscinfrt,
prp_rnt_id,
cvm_id
FROM twn_rate r1
WHERE ROWNUM<1000000
AND suppliercode != 'TWN'
AND (prd_dip_id=0 OR prd_dip_id IN (70154, 70157, 70155, 70156, 70159, 70174, 70211, 70212, 70268, 70213, 70215, 70216, 70217, 70229, 70281, 70267, 70272, 70153))
AND src_code IN ('B','H','L','M','N','Q','T','V','X','S','W','Y')
AND srt_code LIKE '%RETURN'
AND productno IN (SELECT productno
FROM twn_product_location l
WHERE location_type='Origin'
AND townno = 42
AND l.DATABASE = r1.DATABASE)
AND productno IN (SELECT productno
FROM twn_product_location l
WHERE location_type='Destination'
AND townno = 460
AND l.DATABASE = r1.DATABASE)
AND ('15-SEP-2004' <= todate
AND '22-SEP-2004' >= fromdate)
AND (!cvm_rtc_id = 0 OR cvm_rtc_id IN ( SELECT rbp_rtc_id
FROM twn_rate_basis_period rb
WHERE cvm_rtc_id = rbp_rtc_id
AND rb.DATABASE=r1.DATABASE
AND ('15-SEP-2004' <= rbp_to_date
AND '22-SEP-2004' >= rbp_from_date) ))
GROUP BY
adult_rate,
DATABASE,
productcode,
productno,
srt_code,
cvm_dip_id,
prp_rnt_id,
cvm_id
)
ORDER BY adult_rate ASC

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > get rid of a field in group by


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway