473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Return MIN and Max for a particular subset

Sample data:

C_STATUS C_PHONE
---------- ----------
ACTIVE 7044649707
ACTIVE 7044640709
ACTIVE 7044649710
PENDING 7044649701
PENDING 7044649702
WORKING 3015805111
WORKING 3015805112
WORKING 3015805113
PENDING 7034640001
PENDING 7034640002
PENDING 7034640003
ACTIVE 7034640709
ACTIVE 7034640710
WORKING 7034645111
WORKING 7034645112
WORKING 7034645113
PENDING 7034649701
PENDING 7034649702

I need min and max phone numbers according to particular set of status.


My output should be ( I don’t what the phone numbers to be in that specific format it can be even 7034649707-7044640709)


C_STATUS C_PHONE

---------- ---------
ACTIVE 7034640707-0710
PENDING 7034649701-9702
WORKING 7034645111-5113
PENDING 7034640001-0003
ACTIVE 7034640709-0710
WORKING 7034645111-5113
PENDING 7034649701-9702

Any ideas ??

thank you for your help
Nanda
Nov 17 '06 #1
2 1567
pragatiswain
96 Expert
Hope the following piece will help. (Not tested)

C_STATUS_TRACK VARCHAR2(20) :=NULL;
C_PHONE_TRACK VARCHAR2(25) := NULL;
C_CNT_TRACK NUMBER(20) := 0;

CURSOR PHONE_STATUS IS
SELECT C_STATUS, C_PHONE, COUNT(*) C_CNT
FROM ####
ORDER BY C_STATUS, C_PHONE

PHONE_STATUS_REC PHONE_STATUS%ROWTYPE;

FOR PHONE_STATUS_REC IN PHONE_STATUS
LOOP

C_CNT_TRACK := C_CNT_TRACK + 1;

IF (PHONE_STATUS_REC.C_STATUS <> C_STATUS_OLD) OR (C_CNT_TRACK = 1) THEN
C_STATUS_TRACK := PHONE_STATUS_REC.C_STATUS;
C_PHONE_TRACK := TO_CHAR(PHONE_STATUS_REC.C_PHONE);
ELSE
BEGIN
IF (PHONE_STATUS_REC.C_PHONE <> C_STATUS_OLD + 1) THEN
C_PHONE_TRACK := C_PHONE_TRAC || '-' || TO_CHAR(PHONE_STATUS_REC.C_PHONE);
INSERT INTO TMP_#### VALUES (C_STATUS_TRACK, C_PHONE_TRACK);
C_STATUS_TRACK := NULL;
C_PHONE_TRACK := 0;
END IF;
END;
END IF;

IF (PHONE_STATUS_REC.C_STATUS = C_CNT_TRACK) AND (C_STATUS_TRACK <> NULL) THEN
C_PHONE_TRACK := C_PHONE_TRAC || '-' || TO_CHAR(PHONE_STATUS_REC.C_PHONE);
INSERT INTO TMP_#### VALUES (C_STATUS_TRACK, C_PHONE_TRACK);
END IF;

C_STATUS_OLD := PHONE_STATUS_REC.C_STATUS;
C_PHONE_OLD := PHONE_STATUS_REC.C_PHONE;

END LOOP;
Nov 17 '06 #2
pragatiswain
96 Expert
Hope the following piece will help. (Not tested)

C_STATUS_TRACK VARCHAR2(20) :=NULL;
C_PHONE_TRACK VARCHAR2(25) := NULL;
C_CNT_TRACK NUMBER(20) := 0;

CURSOR PHONE_STATUS IS
SELECT C_STATUS, C_PHONE, COUNT(*) C_CNT
FROM ####
ORDER BY C_STATUS, C_PHONE

PHONE_STATUS_REC PHONE_STATUS%ROWTYPE;

FOR PHONE_STATUS_REC IN PHONE_STATUS
LOOP

C_CNT_TRACK := C_CNT_TRACK + 1;

IF (PHONE_STATUS_REC.C_STATUS <> C_STATUS_OLD) OR (C_CNT_TRACK = 1) THEN
C_STATUS_TRACK := PHONE_STATUS_REC.C_STATUS;
C_PHONE_TRACK := TO_CHAR(PHONE_STATUS_REC.C_PHONE);
IF (PHONE_STATUS_REC.C_STATUS <> C_STATUS_OLD) THEN
C_PHONE_TRACK := C_PHONE_TRACK || '-' || C_PHONE_OLD;
INSERT INTO TMP_#### VALUES (C_STATUS_TRACK, C_PHONE_TRACK);
C_STATUS_TRACK := NULL;
C_PHONE_TRACK := 0;
ENDIF;
ELSE
BEGIN
IF (PHONE_STATUS_REC.C_PHONE <> C_STATUS_OLD + 1) THEN
C_PHONE_TRACK := C_PHONE_TRAC || '-' || TO_CHAR(PHONE_STATUS_REC.C_PHONE);
INSERT INTO TMP_#### VALUES (C_STATUS_TRACK, C_PHONE_TRACK);
C_STATUS_TRACK := NULL;
C_PHONE_TRACK := 0;
END IF;
END;
END IF;

IF (PHONE_STATUS_REC.C_STATUS = C_CNT_TRACK) AND (C_STATUS_TRACK <> NULL) THEN
C_PHONE_TRACK := C_PHONE_TRAC || '-' || TO_CHAR(PHONE_STATUS_REC.C_PHONE);
INSERT INTO TMP_#### VALUES (C_STATUS_TRACK, C_PHONE_TRACK);
END IF;

C_STATUS_OLD := PHONE_STATUS_REC.C_STATUS;
C_PHONE_OLD := PHONE_STATUS_REC.C_PHONE;

END LOOP;[/quote]
Nov 18 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: les_ander | last post by:
Hi, I have many set objects some of which can contain same group of object while others can be subset of the other. Given a list of sets, I need to get a list of unique sets such that non of the...
29
by: Chris Dutrow | last post by:
I searched around on the net for a bit, couldn't find anything though. I would like to find some code for a function where I input A Range Of Integers For example: Function( 1, 100 ); And the...
9
by: Steve | last post by:
Hello (and a happy new year) I'm quite new to C++ and have to programm something for school and can't get my head around a couple of things, but at the moment this one is the most important for...
2
by: Dave | last post by:
Hello all, I have a class that contains a large number of discrete pieces of state information. Any combination of these member variables might be valid for a given object. Any given member...
1
by: Robert Neville | last post by:
The solution to my dilemma seems straight-forward, yet my mind has not been forthcoming with a direct route. My Project form has a tab control with multiple sub-forms; these distinct sub-forms...
52
by: Robert | last post by:
Alright, here's my situation: if i use malloc like: char *mystring; mystring = (char *)malloc(80); return mystring; free(mystring);
35
by: ytrama | last post by:
Hi, I have read in one of old posting that don't cast of pointer which is returned by the malloc. I would like to know the reason. Thanks in advance, YTR
5
by: Ronald S. Cook | last post by:
From my business tier (class) I get back an IQueryable<Penof data. Here is my client code that works fine: PenClass penClass = new PenClass(); IQueryable<Penpens = penClass.SelectPens(); ...
101
by: Tinkertim | last post by:
Hi, I have often wondered if casting the return value of malloc() (or friends) actually helps anything, recent threads here suggest that it does not .. so I hope to find out. For instance : ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.