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:
Dell PowerEdge Servers
  #1  
Old February 9th, 2004, 12:30 AM
raseena raseena is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 11 raseena User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up GROUP BY prblm

hi,

please read the following query

SQL> ed
Wrote file afiedt.buf

1 SELECT FUNC_CODE, MAX(EFFECTIVE_DATE) as MX_DATE FROM TCBN_FUNCTION_MST WHERE
2 UPPER(FUNC_CODE) LIKE('%') AND FUNC_CODE IN (SELECT DISTINCT
3 FUNC_CODE FROM TCBN_OPER_FUNC_MST WHERE OPER_CODE LIKE ('001')) AND
4 UPPER(FUNC_DESC_INST) LIKE('%') AND UPPER(FUNC_ID) LIKE('%') AND
5 UPPER(DELETED) NOT LIKE 'Y' OR UPPER(DELETED) IS NULL
6* GROUP BY FUNC_CODE
SQL> /

FUN MX_DATE
--- ---------
001 20-JAN-04
003 05-JAN-04
005 03-JAN-04
008 20-JAN-04


In the above query i want 2 add more fields, but i want the same output 2 be displayed. here is the query i tried..but itz grouping by all the fields...



SQL> ed
Wrote file afiedt.buf

1 SELECT FUNC_CODE, FUNC_DESC_INST, MAX(EFFECTIVE_DATE) as MX_DATE
2 FROM TCBN_FUNCTION_MST
3 WHERE
4 UPPER(FUNC_CODE) LIKE('%') AND FUNC_CODE IN (SELECT DISTINCT
5 FUNC_CODE FROM TCBN_OPER_FUNC_MST WHERE OPER_CODE LIKE ('001')) AND
6 UPPER(FUNC_DESC_INST) LIKE('%') AND UPPER(FUNC_ID) LIKE('%') AND
7 UPPER(DELETED) NOT LIKE 'Y' OR UPPER(DELETED) IS NULL
8* GROUP BY FUNC_CODE, FUNC_DESC_INST
SQL> /

FUN FUNC_DESC_INST MX_DATE
--- ---------------------------------------- ---------
001 BANK RETURNS 20-JAN-04
003 DISCOUNT HOUSE RETURNS 05-JAN-04
005 TED 02-JAN-04
005 Premium Assessment 03-JAN-04
008 OFID 04-JAN-04
008 PRE EXAMINATION REQUIREMENTS 20-JAN-04

6 rows selected.


any kind of solutions are highly appreciated.

Reply With Quote
  #2  
Old February 9th, 2004, 01:06 AM
sachinborkar sachinborkar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 99 sachinborkar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 12 m 17 sec
Reputation Power: 5
Problem is not with the Query but whith how the data is stored. Seems like there are 2 Description for the Same Function Code (005, 008) No matter what you do the output will be same for the Second Query.
hence Make sure that there is one and only one description for each function code. Then you should get the Same Output as your first query

Reply With Quote
  #3  
Old February 9th, 2004, 01:49 AM
raseena raseena is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 11 raseena User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Actually the function code's will be repeating and it will have different description also.
But i want to display only those function code with its corresponding description where the max(effective) date comes.

so any more suggestions?

Reply With Quote
  #4  
Old February 9th, 2004, 02:34 AM
sachinborkar sachinborkar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 99 sachinborkar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 12 m 17 sec
Reputation Power: 5
Try This Query this should give you the result as you want:

SELECT B.FUNC_CODE, a.FUNC_DESC_INST, b.EFFECTIVE_DATE as MX_DATE
FROM TCBN_FUNCTION_MST A, (Select Func_Code, MAX (EFFECTIVE_DATE) AS EFFECTIVE_DATE FROM FROM TCBN_FUNCTION_MST GROUP BY FUNC_CODE) B

WHERE A.FUNC_CODE = B.FUNC_CODE
AND A.Effective_Date = b.Effective_Date
AND UPPER(A.FUNC_CODE) LIKE('%')

AND A.FUNC_CODE IN (SELECT DISTINCT
FUNC_CODE FROM TCBN_OPER_FUNC_MST WHERE OPER_CODE LIKE ('001')) AND
UPPER(FUNC_DESC_INST) LIKE('%') AND UPPER(FUNC_ID) LIKE('%') AND
UPPER(DELETED) NOT LIKE 'Y' OR UPPER(DELETED) IS NULL

Reply With Quote
  #5  
Old February 9th, 2004, 04:15 AM
raseena raseena is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 11 raseena User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
THANX FOR UR REPLY.
BUT THAT QUERY GIVES ME MULTIPLE RECORDS.

Here is the worked query

SELECT B.FUNC_CODE, a.FUNC_DESC_INST
FROM TCBN_FUNCTION_MST A,
(Select Func_Code, MAX (EFFECTIVE_DATE) AS EFFECTIVE_DATE
FROM TCBN_FUNCTION_MST
WHERE UPPER(FUNC_CODE) LIKE('%')
AND FUNC_CODE IN (SELECT DISTINCT
FUNC_CODE FROM TCBN_OPER_FUNC_MST WHERE OPER_CODE LIKE ('001')) AND
UPPER(FUNC_DESC_INST) LIKE('%') AND UPPER(FUNC_ID) LIKE('%') AND
UPPER(DELETED) NOT LIKE 'Y' OR UPPER(DELETED) IS NULL
GROUP BY Func_Code)B
WHERE A.FUNC_CODE = B.FUNC_CODE
AND A.Effective_Date = b.Effective_Date
/

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > GROUP BY prblm


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 6 hosted by Hostway