Help selecting from records with duplicate fields
Test_table2 is shown below with the sql to create it.
I need to:
Identify duplicate address_keys
Within that set of duplicate address_keys, select only if HH_Income is the same between the two records and the HH_Age difference is less than 10
Now the duplicate set matches the necessary criteria, and I want to select from these duplicate address_keys, only the one with the most recent verification date
The purpose of this is to infer cohabiting couples. In the large set of data we receive, for each HH_key if the people have the same last name they are all listed under the same HH_Key, but if they do not have same last name but live together, they will be listed as separate households (HH_key) but with the same address_key. A further validator is if each HH_key reports the same HH_Income and if they are close in age. We then only want to mail to one of the people, so we choose the one that has the most recent verification date.
The result I would expect here, using the table I provided, would be
HH_Key
Address_Key
HH_Type
HH_Income
Age
Verification_Date
1234
1111
10
6
50
10-Jun-13
Can you help?
HH_Key
Address_Key
HH_Type
HH_Income
Age
Verification_Date
1234
1111
10
6
50
10-Jun-13
5678
1111
11
6
49
15-Jun-12
5544
2222
10
6
65
10-Apr-13
7788
1111
3
3
25
10-Jun-13
9898
3333
10
6
45
18-Jun-13
CREATE TABLE test_table2
(HH_key varchar(20),
address_key varchar(20),
HH_type varchar(2),
HH_Income varchar(2),
HH_age varchar(2),
Verification_date Date
INSERT INTO test_table2
(HH_Key, Address_key, HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(1234, 1111, 10, 6, 50, '10-Jun-13');
INSERT INTO test_table2
(HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(5678, 1111, 11, 6, 49, '15-Jun-12');
INSERT INTO test_table2
(HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(5544, 2222, 10, 6, 65, '10-Apr-13');
INSERT INTO test_table2
(HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(7788, 1111, 3, 3, 25, '10-Jun-13');
INSERT INTO test_table2
(HH_Key, Address_key,HH_Type, HH_Income, HH_Age, Verification_date)
VALUES
(9898, 3333, 10, 6, 45, '18-Jun-13');
I really like the results this gave, because it allows me to create a view now that contains the pair in one record. Thanks for this response. I think I did post the result that I was looking for which would be the one record that we would mail to: Once I create the view with one record for each pair, then I would just need to select the verification date that was greatest with the related data. Would that be the best approach to take? The fact that I now have a single record for each pair is excellent!
The result I would expect here, using the table I provided, would be
HH_Key
Address_Key
HH_Type
HH_Income
Age
Verification_Date
1234
1111
10
6
50
10-Jun-13
Similar Messages
-
Select from three tables (one field)
Dear Friends
I have start-of-selection.
select * from qals into corresponding fields of table itab where enstehdat in s_tarih.
loop at itab.
select matnr ntgew from mara into (mara-matnr, mara-ntgew) where matnr eq itab-matnr.
select matnr zfirmaadi ztezgah1 from zomt_malz into (zomt_malz-matnr, zomt_malz-zfirmaadi, zomt_malz-ztezgah1)
where matnr eq itab-matnr.
move-corresponding itab to itab2.
itab2-zfirmaadi = zomt_malz-zfirmaadi.
itab2-matnr = zomt_malz-matnr .
itab2-ztezgah1 = zomt_malz-ztezgah1.
itab2-ntgew = mara-ntgew.
if sy-subrc = 0.
append itab2.
endif.
endselect.
endselect.
endloop.
end-of-selection.
And I want to get unique matnr from this qals,zomt_malz, mara .
Your helps will be very appreciated.hi,
never use select statemnts inside loop.
use FOR ALL ENTRIES.
look this code.
select * from qals
into corresponding fields of table itab
where enstehdat in s_tarih.
select matnt ntgew
from mara
into table itab_mara
for all entries in itab
where
matnr = itab-matnr.
select matnr zfirmaadi ztezgah1
from zomt_malz into table itab_ ztezgah1
for all entries in itab
where
matnr = itab-matnr.
loop at itab.
move-corresponding itab to itab2.
read table itab_mara with key matnr = itab-matnr.
if sy-subrc = 0.
itab2-ntgew = mara-ntgew.
endif.
read table itab_ ztezgah1 with key matnr = itab-matnr.
if sy-subrc = 0.
itab2-zfirmaadi = zomt_malz-zfirmaadi.
itab2-matnr = zomt_malz-matnr .
itab2-ztezgah1 = zomt_malz-ztezgah1.
endif.
append itab2.
clear itab2.
endloop.
regrds
anver
if helped mark points -
There is already a record with duplicate customer/vendor reference number
Dear Expert,
Person "A" reject the Sale Order now Person "B" edit same SO and again send to "A",now second time "A" approval
"B" in aleart msg go to that approval,press "add" button got information (error)
"there is already a record with duplicate customer/vendor reference number"
what shud i do ?
and why in aleart message box two entry for same SO
1st is reject but show SO draft [approved]
2nd is approval ...
Thankshi,
U can change radio button option in per document tab of document settings for sales order,
Either change it to without warning / warning only When duplicated customer reference no. occurs.
Modify customer reference number by including dot at end. -
How to select records with certain fields unique while others not
Hi,
For example, I have table with 6 columns, called 'A', 'B', 'C', 'D', 'E', 'F'. There's no unique constraint built-in, and I would like to select records that have both column 'A' and 'B' unique. What should the sql statement look like?
Columns 'C', 'D', 'E', 'F' can have same data in different records or null, not a concern.
Thanks.select A, B, max(C), max(D), max(E), max(F) from <your_tab>
group by A, B
select * from (select t.*, row_number() over (partition by A,B order by null) rn from <your_tab> t)
where rn=1they are not the same, but seem to meet your needs both. -
Sharepoint 2010 Content Deployemnt Job issue with duplicate fields in User information List
Hi friends,
I am facing below issue with the content deployment job.
It was working earlier. But now since from couple of days all the content deployment jobs in production environment are failing with below error.
Field name already exists. The name used for this field is already used by another field in the list. Select another name and try again.
ObjectName="User Information List".
When I check the fields in User information list in targeted site, I found couple of columns are dupicate like "ask me about",first name","Last name" etc.
Do i Need to drop target site collection or recreate with fresh content deployment job.
Please suggest.
Please help .
Regards
SubratHi,
According to your post, my understanding is that you got duplicate field error.
Based on the error message, you can try to use the following code sample to remove duplicate records, and check whether it works:
http://social.msdn.microsoft.com/Forums/en-US/sharepointgeneralprevious/thread/41ee04bd-91fb-4bf9-932a-bac42c56c357
Here is a similar issue, you can also use the ‘RemoveDuplicateColumn64’ provided:
http://sharepointsurfer.wordpress.com/2012/04/27/how-to-fix-publishing-site-content-deployment-error-duplicate-first-name-column/
What’s more, as you had said, you can recreate a site with a fresh deployment job.
Thanks & Regards,
Jason
Jason Guo
TechNet Community Support -
Select Random Records with Group By?
Hi,
I currently select random records by using this type of SQL:
(SELECT *
FROM ( SELECT *
FROM ( SELECT *
FROM TABLEA
ORDER BY dbms_random.value
WHERE ROWNUM <= 100
Based on the following data, I now want to still pick out random records but I only want 1 record from the same ID and START_DATE but where the FLAG could be Y or N.
So with grouping by ID and START_DATE, I need to still be able to choose the record if it has anything from 1 entry or 10 entries per ID and START_DATE.
Could this be performed with a GROUP BY?
ID START_DATE FLAG
1 12/12/2005 Y
1 12/12/2005 N
1 12/12/2005 N
1 30/12/2005 Y
1 30/12/2005 N
1 30/12/2005 N
2 10/10/2005 Y
2 07/07/2005 Y
Thanks for any help.
DanielTry this [not tested]:
SELECT *
FROM
(SELECT *
FROM
( SELECT
ID
,START_DATE
,FLAG
,ROW_NUMBER() OVER
(PARTITION BY ID,START_DATE ORDER BY dbms_random.value) RN
FROM TABLEA
ORDER BY dbms_random.value
WHERE RN = 1
AND ROWNUM <= 100
; -
How to Ignore records having duplicate field value
Hi,
I have a fixed length flat file having multiple records.
Ex:
1000423421A8090
1000802421A8091
1000454421B8092
1000412421C8093
The first 2 record has A. So I have to take only one out of first two record and ignore the second one. I mean if there is any duplicate field at 11th position then I have to select only one record.
Can you please let me know how to handle this.
Thanks
MukeshMukesh,
Use the following UDF to achieve the same.
<u><b><i>getchar</i></b></u>
char ret = Values.charAt(10);
return ""ret"";
<u><b><i>Maptarget</i></b></u>
//write your code here
int len = Values.length;
String char_at="";
String pos="";
for(int j=0;j<len;j++)
if(j==0){
result.addValue(Values[j]);
else
char_at= ""+ Values[j-1].charAt(10);
pos=""+Values[j].charAt(10);
if(!char_at.equals(pos))
result.addValue(Values[j]);
<b><i><u>Mapping Logic</u></i></b>
1. Use sort by key function
in the first parameter map - Source -UDF(getchar)
in the second parameter map -Source
2.Map the output of sortbykey to UDF(Maptarget)
3.Finally Map the o/p of UDF to target.
I checked it, its working as per your reqmt.
If you have any doubts reply me I'll help you out.
Note: In UDF(MapTarget) use Queue
Best Regards,
Raj. -
Need help in multitrack recording with Audigy 4 pro
Hi there,?I have an audigy 4 pro soundplaster caed and use it with Cubase LE. I haven't figured out yet how to record the several tracks onto seperate?channels simultaneously. All inputs of the soundcard work and I know how to assign the channels to the tracks in cubase. But in the end the same is coming out of all... I have figured out that in the Audigy mixing console you need to select the input source first, but I only can select one. If I select 'what you hear' I can use all - but not seperated. Someone knows how to deal with it'sAny help hugely appreciated
!!! Ggun wrote:
Hi,
wow, I got a big step further with this, thanks.
Yes, after pulling the window down ai discovered many moretracks. I also managed to get a signal in cubase by pressing the monitor item. And I could remap inputs. I got my input 3 set up fine. It's in the devie dislaplyed as L and R but witchever I choose works.
But for my second track it only lets my choose the other otpion of the same input (if trach one is Line 3L its has to be Line 3R for the other input. I did remap the track to to use line in but no signal and in the windows control mixer I still can only select one recording source but it doesn't correspondent with cubase, cubase records line in 3 whichever thing is ticked in the windows mixer.
Line in does go into my soundcards as I can hear it through the speakers but no further.
I uploaded the manual onto my own webspace, seemed the simplest thing: http://www.magicviolin.co.uk/Cubase%20LE%20manual.pdf
Thanks so much again, I actually feel slightly positi've now that I might it even get working...
The Manual cleared a lot. LE seem to have a bit stripped settings compared to SX, but the logic seem to be the same (maybe LE is ~ SE/SX .0).
As you have Audigy 4 Pro there, you should see quite many input channels listed on "VST Inputs" -panel. The bad thing seems to be, you have no names for inputs but they're listed as PCI REC & 2, PCI REC 2 & 3, etc. mono pairs. Now you need to examine which one is which (i.e. does PCI REC & 2 mean Audigy's Line-In L/R, PCI REC 3 & 4 as LineIn 2 L/R, etc.). See below.
NOTE: Inputs being as pairs of L/R channels means you can record to 2 tracks using one stereo input w/ mono connections (i.e. guitar through LineIn L and Bass through LineIn R). Tracks need to be set as mono. When you have one stereo connection or track set to stereo, you get the same signal from LineIn L and R to those tracks you have set the LineIn L or R as input source.
CT Surround Mixer settings:
- open those source channels you're using
- if you use any Creative ASIO driver the .rec source selector has no effect
Project settings:
With any Creative ASIO driver you need to set (Project properties)
- bit-depth (record format) to 6-bit (or 24-bit if using "ASIO 24/96 driver") and
- samplerate to 48000 Hz (or to 96 kHz when using the "ASIO 24/96 driver")
See - Activating and selecting VST Inputs - Manual p.2-25 ->:
- you need to know which inputs are included to AnalogMix() --> you see these listed on Creative Surround Mixer --> rec. source selector.
- give those inputs (label) the same name they appear on Creative Surround Mixer (i.e. Auxiliary, Line-In, Microphone, etc.)
--> you need to do these settings once if you save the (empty) project as a template
See - Mixer p. 7.37 (Audio channel strips)-->:
- here you can select the Input -channels (remember, which ones are in same group "AnalogMix ()" because they uses the same signal path and therefore gets recorded to all tracks having this source selected)
Hope you get things cleared, and remember save a well functioning project as Template (you can make templates with various settings (like one for 6/48 w/ audio tracks, other for 24/96 w/ audio tracks, and next for 6/48 w/ audio and MIDI tracks, etc.).
If you need 'some' VST effects/instruments for your recordings, KVR is best place to start from.
jutapaMessage Edited by jutapa on 04-06-2006 0:43 PM -
To capture the selected rows along with edited field contents in alv report
Dear All,
I do have requirement where, in alv report output one field is editable and need to save the content of the edited field along with the selected rows.
For example If there are 10 records displayed in the alv output with 20 fields.
Out of this 20 fields one field (say XYZ) is editable. Also i have already created a new pushbutton (say ABC) on alv output. Now in the alv output if we maintain some value in the field (XYZ ) for the 2nd and 4th record and select this two records, and when clicked on the pushbutton (ABC) it has to update the DB table.
I am using the Func Module 'REUSE_ALV_GRID_DISPLAY'.
Your early reply with sample code would be appreciated.
Thanks in Advance.HI Naveen ,
There is an import parameter "i_callback_program" in the function module,
plz pass the program name to it.
Capture the command by passing a field of type sy-ucomm to "I_CALLBACK_USER_COMMAND ". Check the returned command and
and program a functionality as desired.
u can try the event double_click or at line selection. there u can use READLINE command to c if the line has been selected.
In case it is , process the code segment.
Regards
Pankaj -
Hi,
Iam trying to use bsak-budat with bseg-gjahr.But lengths are not same. I had offsetting with budat.But values are not matching...could any one tell me how to do that?
points guaranteed
cheers
kaki
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR BUZEI BUDAT BLDAT
CPUDT WAERS BLART BSCHL SHKZG DMBTR WRBTR SGTXT HKONT SKFBT
from bsak
into corresponding fields of table t_bsak
where
lifnr in s_lifnr and
BUKRS in s_bukrs and
budat le s_budat and augdt in s_augdt.
loop at t_bsak.
l_year = t_bsak-budat(4).
endloop.
CHECK NOT t_bsak[] IS INITIAL.
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR
SHKZG DMBTR WRBTR SGTXT SKFBT KOSTL BSCHL HKONT BUZEI
into corresponding fields of table t_bseg from bseg
FOR ALL ENTRIES IN t_bsak
where belnr = t_bsak-belnr and
gjahr = l_year and " xxxxxx
bukrs = t_bsak-bukrs.Define a field I_YEAR in int table T_BSAK.
DATA Begin of t_BSAK,
I_YEAR LIKE BSEG-GJAHR,
end of t_bsak.
loop at t_bsak.
t_bsak-l_year = t_bsak-budat(4).
modify t_bsak.
endloop.
Then
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR
SHKZG DMBTR WRBTR SGTXT SKFBT KOSTL BSCHL HKONT BUZEI
into corresponding fields of table t_bseg from bseg
FOR ALL ENTRIES IN t_bsak
where belnr = t_bsak-belnr and
gjahr = t_bsak-i_year and " xxxxxx
bukrs = t_bsak-bukrs.
Alternatively why not select gjahr from BSAK .
Cheers .
Sanjay -
PROBLEM WITH Select * from table_name with JDBC
Hello,
I am using thin driver. The problem that i am having is as
follows.
when i execute select * from any_table_name from within java
code i only get FIRST row back. I am using Employee.java example.
Is there something else i should do?
Alex
nullHi Alex,
I am writing a client application with Java. Everything works
really well, but - same problem as you had (I know, you solved it
- that's why I'm writing :) - reading only first column. Actually
it works fine on its own, but when embedded in my java app -
that's when I get the first column displayed.
Also executing "select * from emp;" gives me a sequence of
numbers (displayed in columns) 20, 30, 30 etc, which are in fact
present as one of the columns when running this query without
java.
I appreciate your help!
Malgosia
Alex Korneyev (guest) wrote:
: Hello,
: I am using thin driver. The problem that i am having is as
: follows.
: when i execute select * from any_table_name from within java
: code i only get FIRST row back. I am using Employee.java
example.
: Is there something else i should do?
: Alex
null -
4.0 EA1 - Cannot select from table with xmltype
Hi,
I have the following table. When doing a select * from horus_owner.horus_objects nothing is shown. This could be reproduced with both 10g and 11g on the database-side.
Regards,
Johannes
-- Wiedergabe von TABLE DDL für Objekt HORUS_OWNER.HORUS_OBJECTS nicht möglich, da DBMS_METADATA internen Generator versucht.
CREATE TABLE HORUS_OWNER.HORUS_OBJECTS
ID NUMBER(32, 0) NOT NULL
, TRE_ID NUMBER(32, 0) NOT NULL
, WRK_ID NUMBER(32, 0) NOT NULL
, NAME VARCHAR2(200 BYTE) NOT NULL
, MOD_TYPE VARCHAR2(10 BYTE) NOT NULL
, LOCKED_BY VARCHAR2(30 BYTE)
, PETRI_XML SYS.XMLTYPE
, AOM_XML SYS.XMLTYPE
, SHM_XML SYS.XMLTYPE
, ORG_XML SYS.XMLTYPE
, ROLE_XML SYS.XMLTYPE
, MIT_XML SYS.XMLTYPE
, RUL_XML SYS.XMLTYPE
, TXT_DATA CLOB
, CREATED DATE NOT NULL
, CREATED_BY VARCHAR2(30 BYTE) NOT NULL
, UPDATED_BY VARCHAR2(30 BYTE)
, UPDATED DATE
, SIM_XML SYS.XMLTYPE
, GLOSSARY_XML SYS.XMLTYPE
, CONSTRAINT OBJ_PK PRIMARY KEY
ID
ENABLE
LOGGING
TABLESPACE HORUS_OWNER_DATA
PCTFREE 10
INITRANS 1
STORAGE
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
) NOCOMPRESS
XMLTYPE PETRI_XML STORE AS CLOB
XMLTYPE AOM_XML STORE AS CLOB
XMLTYPE SHM_XML STORE AS CLOB
XMLTYPE ORG_XML STORE AS CLOB
XMLTYPE ROLE_XML STORE AS CLOB
XMLTYPE MIT_XML STORE AS CLOB
XMLTYPE RUL_XML STORE AS CLOB
LOB (TXT_DATA) STORE AS SYS_LOB0000024538C00021$$
ENABLE STORAGE IN ROW
CHUNK 8192
RETENTION
NOCACHE
LOGGING
XMLTYPE SIM_XML STORE AS CLOB
XMLTYPE GLOSSARY_XML STORE AS CLOBALTER TABLE HORUS_OWNER.HORUS_OBJECTS
ADD CONSTRAINT OBJ_UK UNIQUE
WRK_ID
, NAME
, TRE_ID
ENABLEALTER TABLE HORUS_OWNER.HORUS_OBJECTS
ADD CONSTRAINT OBJ_TRE_FK FOREIGN KEY
TRE_ID
REFERENCES HORUS_OWNER.HORUS_TREE_NODES
ID
ENABLEALTER TABLE HORUS_OWNER.HORUS_OBJECTS
ADD CONSTRAINT AVCON_1243352806_MOD_T_000 CHECK
(MOD_TYPE
IN ('EMP', 'ROL', 'ENT', 'OCH', 'XML', 'SHM', 'OSM', 'BUM', 'BOM',
'BEH', 'KPI', 'RIS', 'SER', 'STR', 'SWO', 'AOM', 'CON', 'GOA', 'BUR'
, 'BPA', 'RES', 'SIM', 'GLO','TEM', 'SAR'))
ENABLECREATE UNIQUE INDEX HORUS_OWNER.OBJ_PK ON HORUS_OWNER.HORUS_OBJECTS (ID ASC)
LOGGING
TABLESPACE HORUS_OWNER_IDX
PCTFREE 10
INITRANS 2
STORAGE
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
NOPARALLEL
CREATE INDEX HORUS_OWNER.OBJ_TRE_FK_I ON HORUS_OWNER.HORUS_OBJECTS (TRE_ID ASC)
LOGGING
TABLESPACE HORUS_OWNER_IDX
PCTFREE 10
INITRANS 2
STORAGE
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
NOPARALLEL
CREATE UNIQUE INDEX HORUS_OWNER.OBJ_UK ON HORUS_OWNER.HORUS_OBJECTS (WRK_ID ASC, NAME ASC, TRE_ID ASC)
LOGGING
TABLESPACE HORUS_OWNER_IDX
PCTFREE 10
INITRANS 2
STORAGE
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
NOPARALLEL
CREATE INDEX HORUS_OWNER.OBJ_WRK_FK_I ON HORUS_OWNER.HORUS_OBJECTS (WRK_ID ASC)
LOGGING
TABLESPACE HORUS_OWNER_IDX
PCTFREE 10
INITRANS 2
STORAGE
INITIAL 65536
NEXT 1048576
MINEXTENTS 1
MAXEXTENTS UNLIMITED
BUFFER_POOL DEFAULT
NOPARALLELNot sure if this helps, but I was trying to come up with some test cases myself and I noticed some strange behavior. 4 simple test cases:
SELECT XMLTYPE('<OUTER><INNER>TEST</INNER></OUTER>') FROM DUAL;
SELECT XMLELEMENT("OUTER", XMLELEMENT("INNER", 'TEST')) FROM DUAL;
SELECT XMLELEMENT("OUTER", XMLAGG(XMLFOREST('TEST' "INNER"))) FROM DUAL;
SELECT XMLQUERY('/OUTER' PASSING XMLTYPE('<OUTER><INNER>TEST</INNER></OUTER>') RETURNING CONTENT) FROM DUAL;
1 and 2 return the xml string in the result grid column. 3 and 4 return (XMLTYPE) with no data in the pop-up editor when double clicking the result. I changed #3 to:
SELECT XMLELEMENT("OUTER", XMLFOREST('TEST' "INNER")) FROM DUAL;
and it returns the XML string.
I used undo to revert back to my original #3 and it started showing the XML string instead of (XMLTYPE) previously observed.
I changed my connection to another schema, ran #3 again, and it went back to (XMLTYPE). I tried to recreate the same behavior using the 2nd schema, but I was unable to get to show the XML string.
In any test case where I was getting the (XMLTYPE), I was not able to see data in the pop-up editor.
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for HPUX: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production -
Help: Selecting * from view takes minutes, query in view takes only seconds
Hello,
I have a view that i created that compiles ok and the query inside of the view only takes 2 seconds to return all the records. But if i try to select * from the view it takes 4-5 minutes to return the results. The explain plan is exactly the same, whether i select * from the view or run the query from within the view. Explain plan listed at bottom of post. Any ideas on where i might be going wrong? Thanks in advance.
The below query returns ~400 rows. If i limit the rows returned to ~200 with this additional line at the very end:
AND TEAM_CATEGORY LIKE '%FSM%'
the query runs in just a few seconds. So the rows returned is not the problem here.
Code:
SELECT /*+ PUSH_PRED( TEAM ) */ NP.ID_NUMBER,
NP.PROSPECT_ID,
NP.PREF_MAIL_NAME PROSPECT,
NP.OFFICER_RATING RATING,
NP.EVALUATION_RATING EVALUATION,
P.ASK_AMT NEXT_ASK,
P.ANTICIPATED_AMT EXPECT,
NP.STRATEGY_DESCRIPTION STRATEGY,
E1.LAST_NAME PROSPECT_MGR,
TEAM.TEAM_CATEGORY,
CASE
WHEN TOPA.SHORT_DESC <> ' ' THEN
'X'
END TOPA,
E.PREF_MAIL_NAME SPOUSE_NAME,
PR.PROSPECT_NAME_SORT SORT_NAME
FROM ADVANCE_NU.NWU_PROSPECT NP,
entity E,
entity E1,
assignment ASSI,
prospect PR,
(select p.proposal_id, p.prospect_id, p.ask_amt, p.anticipated_amt
from proposal p
where p.active_ind = 'Y'
AND (p.stop_date IS NULL OR p.stop_date > sysdate)) P,
(SELECT PC.PROSPECT_ID ID, TP.SHORT_DESC
FROM PROSPECT_CATEGORY PC, TMS_PROSPECT_CATEGORY TP
WHERE PC.PROSPECT_CATEGORY_CODE = TP.PROSPECT_CATEGORY_CODE
AND pc.prospect_category_code = 'TOP') TOPS,
(SELECT PC.PROSPECT_ID ID, TP.SHORT_DESC
FROM PROSPECT_CATEGORY PC, TMS_PROSPECT_CATEGORY TP
WHERE PC.PROSPECT_CATEGORY_CODE = TP.PROSPECT_CATEGORY_CODE
AND pc.prospect_category_code = 'TFP') TOPA,
(SELECT ID,
CASE WHEN count(TEAM_CAT) >= 1 THEN MAX(DECODE(CT, 1, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 2 THEN ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 3 THEN ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 4 THEN ', ' || MAX(DECODE(CT, 4, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 5 THEN ', ' || MAX(DECODE(CT, 5, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 6 THEN ', ' || MAX(DECODE(CT, 6, TEAM_CAT)) ELSE ' ' END
TEAM_CATEGORY
FROM (SELECT PC.PROSPECT_ID ID,
ROW_NUMBER() OVER(PARTITION BY PC.PROSPECT_ID ORDER BY PC.PROSPECT_CATEGORY_CODE ASC) CT,
TP.SHORT_DESC TEAM_CAT
FROM PROSPECT_CATEGORY PC, TMS_PROSPECT_CATEGORY TP
WHERE PC.PROSPECT_CATEGORY_CODE = TP.PROSPECT_CATEGORY_CODE
AND PC.PROSPECT_CATEGORY_CODE NOT IN ('TOP', 'TFP'))
GROUP BY ID) TEAM
WHERE NP.PROSPECT_ID = P.PROSPECT_ID(+)
AND NP.spouse_id = E.id_number(+)
AND NP.prospect_id = PR.prospect_id
AND NP.PROSPECT_ID = TOPS.ID
AND NP.PROSPECT_ID = TEAM.ID(+)
AND NP.prospect_id = TOPA.ID(+)
AND NP.PROSPECT_ID = ASSI.PROSPECT_ID(+)
AND ASSI.ASSIGNMENT_ID_NUMBER = E1.ID_NUMBER(+)
AND ASSI.ASSIGNMENT_TYPE(+) = 'PM';Explain plan:
SELECT STATEMENT, GOAL = CHOOSE 346 1 369 346
HASH JOIN OUTER 346 1 369 346
HASH JOIN OUTER 332 1 330 332
NESTED LOOPS OUTER 326 1 190 326
NESTED LOOPS OUTER 325 1 171 325
NESTED LOOPS OUTER 323 1 152 323
NESTED LOOPS OUTER 322 1 119 322
NESTED LOOPS 320 1 90 320
NESTED LOOPS 319 1 67 319
NESTED LOOPS 319 484568 24712968 319
INDEX UNIQUE SCAN ADVANCE ZZ_ADV_TABLE_KEY0 1 1 8 1
TABLE ACCESS FULL ADVANCE_NU NWU_PROSPECT 318 484568 20836424 318
TABLE ACCESS BY INDEX ROWID ADVANCE PROSPECT_CATEGORY 1 16
INDEX RANGE SCAN ADVANCE PROSPECT_CATEGORY_KEY2 1
TABLE ACCESS BY INDEX ROWID ADVANCE PROSPECT 1 1 23 1
INDEX UNIQUE SCAN ADVANCE PROSPECT_KEY0 1
VIEW PUSHED PREDICATE RPT_ACEPONIS 2 1 29
NESTED LOOPS 2 1 40 2
TABLE ACCESS BY INDEX ROWID ADVANCE ZZ_ADV_TABLE 2 1 24 2
INDEX UNIQUE SCAN ADVANCE ZZ_ADV_TABLE_KEY0 1 1 1
TABLE ACCESS BY INDEX ROWID ADVANCE PROSPECT_CATEGORY 1 16
INDEX RANGE SCAN ADVANCE PROSPECT_CATEGORY_KEY2 1
TABLE ACCESS BY INDEX ROWID ADVANCE ENTITY 1 1 33 1
INDEX UNIQUE SCAN ADVANCE ENTITY_KEY0 1
TABLE ACCESS BY INDEX ROWID ADVANCE ASSIGNMENT 2 1 19 2
INDEX RANGE SCAN ADVANCE ASSIGN_PROSPECT_KEY0 1 3 1
TABLE ACCESS BY INDEX ROWID ADVANCE ENTITY 1 1 19 1
INDEX UNIQUE SCAN ADVANCE ENTITY_KEY0 1
VIEW RPT_ACEPONIS 5 1 140
SORT GROUP BY 5 1 48 5
VIEW RPT_ACEPONIS 5 1 48
WINDOW SORT 5 1 40 5
NESTED LOOPS 2 1 40 2
TABLE ACCESS FULL ADVANCE PROSPECT_CATEGORY 2 1 16 2
TABLE ACCESS BY INDEX ROWID ADVANCE ZZ_ADV_TABLE 1 24
INDEX UNIQUE SCAN ADVANCE ZZ_ADV_TABLE_KEY0 1
VIEW RPT_ACEPONIS 13 170 6630
SORT UNIQUE 13 170 32980 7
UNION-ALL
TABLE ACCESS FULL ADVANCE PROPOSAL 3 125 24250 3
TABLE ACCESS FULL ADVANCE PROPOSAL 3 45 8730 3Message was edited by:
user624909
Message was edited by:
user624909
Message was edited by:
AndyCepI'm no expert. Hopefully, someone else will chime in.
A couple points though:
1) (select p.*
from proposal p
where p.active_ind = 'Y'
AND p.stop_date > sysdate
union
select p.*
from proposal p
where p.active_ind = 'Y'
AND p.stop_date is null) P,
is using UNION. It should probably be a UNION ALL, or even better:
(select p.*
from proposal p
where p.active_ind = 'Y'
AND (p.stop_date IS NULL OR p.stop_date > sysdate)
2) select p.*
Do not use * in a VIEW. In fact, never use it outside EXISTS, COUNT(*) and ad hoc queries.
Use a COLUMN-list instead. Always use a COLUMN-list.
3)
The CASE statement has no ELSE, and is redundant.
CASE
WHEN count(TEAM_CAT) = 1 THEN MAX(DECODE(CT, 1, TEAM_CAT))
WHEN count(TEAM_CAT) = 2 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT))
WHEN count(TEAM_CAT) = 3 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 3, TEAM_CAT))
WHEN count(TEAM_CAT) = 4 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 4, TEAM_CAT))
WHEN count(TEAM_CAT) = 5 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 4, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 5, TEAM_CAT))
WHEN count(TEAM_CAT) = 6 THEN MAX(DECODE(CT, 1, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 4, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 5, TEAM_CAT)) || ', ' || MAX(DECODE(CT, 6, TEAM_CAT))
END TEAM_CATEGORY
How about something like:
CASE WHEN count(TEAM_CAT) >= 1 THEN MAX(DECODE(CT, 1, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 2 THEN ', ' || MAX(DECODE(CT, 2, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 3 THEN ', ' || MAX(DECODE(CT, 3, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 4 THEN ', ' || MAX(DECODE(CT, 4, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 5 THEN ', ' || MAX(DECODE(CT, 5, TEAM_CAT)) ELSE ' ' END
|| CASE WHEN count(TEAM_CAT) >= 6 THEN ', ' || MAX(DECODE(CT, 6, TEAM_CAT)) ELSE ' ' END
TEAM_CATEGORY
4) I have to ask. Have you run statistics lately?
5) Did you really alias a TABLE as "***"? Please tell me that is a formatting error.
6) Are you sure you need all those outer joins? -
Insert problem using a SELECT from table with a index by function TRUNC
I came across this problem when trying to insert from a select statement, the select returns the correct results however when trying to insert the results into a table, the results differ. I have found a work around by forcing an order by on the select, but surely this is an Oracle bug as how can the select statements value differ from the insert?
Platform: Windows Server 2008 R2
Oracle 11.2.3 Enterprise edition
(I have not tried to replicate this on other versions)
Here are the scripts to create the two tables and source data:
CREATE TABLE source_data
ID NUMBER(2),
COUNT_DATE DATE
CREATE INDEX IN_SOURCE_DATA ON SOURCE_DATA (TRUNC(count_date, 'MM'));
INSERT INTO source_data VALUES (1, TO_DATE('20120101', 'YYYYMMDD'));
INSERT INTO source_data VALUES (1, TO_DATE('20120102', 'YYYYMMDD'));
INSERT INTO source_data VALUES (1, TO_DATE('20120103', 'YYYYMMDD'));
INSERT INTO source_data VALUES (1, TO_DATE('20120201', 'YYYYMMDD'));
INSERT INTO source_data VALUES (1, TO_DATE('20120202', 'YYYYMMDD'));
INSERT INTO source_data VALUES (1, TO_DATE('20120203', 'YYYYMMDD'));
INSERT INTO source_data VALUES (1, TO_DATE('20120301', 'YYYYMMDD'));
INSERT INTO source_data VALUES (1, TO_DATE('20120302', 'YYYYMMDD'));
INSERT INTO source_data VALUES (1, TO_DATE('20120303', 'YYYYMMDD'));
CREATE TABLE result_data
ID NUMBER(2),
COUNT_DATE DATE
);Now run the select statement:
SELECT id, TRUNC(count_date, 'MM')
FROM source_data
GROUP BY id, TRUNC(count_date, 'MM')You should get the following:
1 2012/02/01
1 2012/03/01
1 2012/01/01Now insert into the results table:
INSERT INTO result_data
SELECT id, TRUNC(count_date, 'MM')
FROM source_data
GROUP BY id, TRUNC(count_date, 'MM');Select from that table and you get:
1 2012/03/01
1 2012/03/01
1 2012/03/01The most recent month is repeated for each row.
Truncate your table and insert with the following statement and the results should now be correct:
INSERT INTO result_data
SELECT id, TRUNC(count_date, 'MM')
FROM source_data
GROUP BY id, TRUNC(count_date, 'MM')
ORDER BY 1, 2;If anyone has encountered this behavior before could you please let me know, I can't see that I am making a mistake as the selects results are correct they should not differ from what is being inserted.
Edited by: user11285442 on May 13, 2013 5:16 AM
Edited by: user11285442 on May 13, 2013 6:15 AMHi,
welcome to the forum. I cannot reproduce the same behavior.
Could you please post the SQLPlus output while executing all commands, like it has been done by S10390?
Also post the output of the following command:
SELECT * FROM v$version;When you put some code or output please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
Formatted code is easier to read.
Regards.
Al -
Selecting from Combobox with only one item
I'm populating Comboboxes based on selections from other
comboboxes. I pick up the selection with the 'change' trigger,
however when you select the top item or if there is only one item,
the change route doesn't work. So I tried to use the 'click' and
even the 'close' triggers instead, but they give me an errors when
I try to access the companion ArrayCollections which hold the IDs
for the items in the list (as commented in the code). Any ideas how
to get this to update with just one selection?
<!-- The first three comboboxes populate the next one in
the list in a 'drilldown' approach -->
<mx:ComboBox minWidth="130" maxWidth="130" id="selectSys"
dataProvider="{sysOps.lastResult.system.data}"
change="fillComboBox(selectSys, selectSub, 'subsystem',
subOps, sysIDs, 1)" rowCount="10" />
<mx:ComboBox minWidth="130" maxWidth="130" id="selectSub"
dataProvider="{subOps.lastResult.system.data}"
change="fillComboBox(selectSub, selectDev, 'devices',
devOps, subIDs, 2)"/>
<mx:HTTPService id="sysOps" useProxy="false" method="GET"
result="sysIDs = sysOps.lastResult.system.id as
ArrayCollection;"
fault="mx.core.Application.application.handleFault(event);"
url="
http://localhost:8080/TomCustodes/rocket"/>
<mx:HTTPService id="subOps" useProxy="false" method="GET"
result="subIDs = subOps.lastResult.system.id as
ArrayCollection;"
fault="mx.core.Application.application.handleFault(event);"
url="
http://localhost:8080/TomCustodes/rocket"/>
// fill destination combobox based on selection from src
combobox
public function fillComboBox(src:ComboBox, dest:ComboBox,
type:String,
serv:HTTPService, idArray:ArrayCollection, element:int) :
void {
// choose ID from the associated ID array with the same
selecetedIndex
// error occurs as the idArray ArrayCollection comes up as
null
var selectedID:String = idArray.getItemAt(src.selectedIndex)
as String;
var params:Object = {};
params[type] = type;
var arg:String = "arg";
var argList:Array = new Array();
if (element > 1) {
var ind:int = selectSys.selectedIndex;
var sysName:String = sysIDs.getItemAt(ind) as String;
argList.push(sysName);
if (element > 2) {
ind = selectSub.selectedIndex;
var subName:String = subIDs.getItemAt(ind) as String;
argList.push(subName);
argList.push(selectedID);
params[arg] = argList;
serv.send(params);
Thanks!I think the way I would go about that is having a result
function for the HTTPServices and set your array collections how
you are. Then after they are set I would check to see if the length
== 1 and if it does then recall your fillComboBox method for the
next combo box since there isn't a way for the user to change the
combo box they might as well have the next one already filled out.
The other approach you could take is after you set your array
collection to your result add dummy items via
myAC.addItemAt({label:"Choose one"}, 0); This will ensure the user
always has an item to change to.
Maybe you are looking for
-
How to get full screen caller pic in ios 7.1
How to get full screen caller pic in ios 7.1.Please help me
-
Exception while setting up approval process
Hi , When I enable the approval process I get the following error . java.lang.ClassCastException at com.sapportals.wcm.control.statemanagement.ApproverControl.isPermissionSet(ApproverControl.java:1620) at com.sapportals.wcm.control
-
Hierarchy or Tree structure Query
Hi, I have to display each level total amount from the below tables We have two tables. Table 1 having the all level columns and table 2 having amount for each level Below are the table scripts and sample data CREATE TABLE LEVEL_TABLE LEVEL1 VARCHAR2
-
Applications not showing / listing
Hi, I am usually tech savvy, but so far I have had no luck at all trying to get the applications to list on my BB Desktop Software v6.1.0.35 - only shows the apps I have installed from or have available on my PC. Does not show any other apps that ar
-
Cannot change desktop image/wallpaper
Forgive me if this is solved elsewhere. The desktop image cannot be changed from the one that came with the unit. I could select another image briefly(my own and stock mac) for a while but recently, when I try to change it,it just flashes the new one