Oracle query - Merging multiple rows into a single row output
Hi All,
I have to have a multiple row output to be converted into a single row output.My current output looks as follows:
ID YR INC_CODE OFFN SCHOOLNO
8006 2002 00175 SC03 12
8006 2002 00175 DC06 12
8006 2002 00175 DC03 12
8006 2002 00175 DC02 12
ID,INCIDENT CODE,OFFENSE are all Primary keys
So I need the output as follows:(IN ONE ROW)
ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 SCHOOLNO
8006 2002 00175 SC03 DC06 DC03 DC02 12
Can you help me on this since have been spinning the wheel and this has to be a query since will have couple of tables join to produce a materialized view.
Thanks in advance
Hi Nigel,
Thanks for the reply I tested out the portion having the decode and I get the output as follows:
ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
8982 2002 2175 DOC01 -----------------------
8982 2002 2175 DOC02-------------------
8982 2002 2175 DOC03------------
8982 2002 2175 DOC06-------
8982 2002 2175 SCV03
There is no value as max for OFFN and each INC_CODE MAY HAVE UP TO A MAX OF 5 OFFN.My query is as follows:
select distinct STU_STUDENT_ID, INC_BEG_SCH_YR,INC_INCIDENT_CODE
, decode(rank() over (partition by INC_CODE order by OFFN),1,OFFN,null) as offn1
, decode(rank() over (partition by INC_CODE order by OFFN),2,OFFN,null) as offn2
, decode(rank() over (partition by INC_CODE order by OFFN),3,OFFN,null) as offn3
, decode(rank() over (partition by INC_CODE order by OFFN),4,OFFN,null) as offn4
, decode(rank() over (partition by INC_CODE order by OFFN),5,OFFN,null) as offn5
from stu_offn where
stu_offn.ID = '8982' and stu_offn.INC_CODE = '2175'
(****Where clause is just given to just check a value)
So as you know I need to just have all the OFFN in a single row ie as follows:
ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
8982 2002 2175 DOC01 DOC02 DOC03 DOC06 SCV03
Can you just give me a step by step procedure to go through this and the table in this case is just 'STU_OFFN'
Thanks for the earlier reply appreciate it!
****Sending this again to show the exact way the output is coming
Similar Messages
-
__Is there a way to 'merge' multiple curves into a single curve?
__Is there a way to 'merge' multiple curves into a single curve?
By this I mean I have file with 2-12 curve layers - I wanted to 'merge' the curves so that I can end up with a single curve with the attributes of many. Maybe is there a script that would do this?I don't mean to be critical, but how do you get to a situation where you have 12 successive Curves layers?
The advantage to a Curves layer is that you can adjust and re-adjust it to your heart's content.
If you're habitually adding new Curves layers one over the other, maybe you should re-evaluate your process of working... Perhaps the way you're thinking you should just work at a high bit depth and do repeated Curves operations on the pixels? Or put some time into retraining yourself to not add a new Curves layer but to manipulate the one that's already there. There are some nice new enhancements (e.g., the "finger" subtool that allows you to choose a spot in the image and manipulate that part of the curve).
Again, I'm not trying to criticize you, just looking to see if maybe there's a way to avoid getting to the point where you need to combine Curves in the first place, since there's no direct "Merge Curves" capability, outside of just stamping a set of image and adjustment layers into pixels. For completeness I suppose I should mention how to do that... You can Stamp any combination of visible layers into a single layer of pixels (effectively combining all the Curves layers et. al.) by pressing Control - Shift - Alt - E.
-Noel -
Merging two rows into a single row
Hi ,
I wish to merge few columns of tow rows into a single row.
if i use union it gives two rows as o/p.
What is the exact sql statement for that?
ThanksHi Sridhar,
This is my code for merging and i used union.
Suggest me good solution.
CREATE OR REPLACE VIEW INSPECTINT.INSPECT_LOC_TRACKING_RPT_VIEW AS
SELECT
VEN_COMPANY_NAME VEN_COMPANY_NAME,
VEN_COMPANY_NAME_2 VEN_COMPANY_NAME_2,
VEN_CONTACT_FIRST_NAME VEN_CONTACT_FIRST_NAME,
VEN_CONTACT_MIDDLE_NAME VEN_CONTACT_MIDDLE_NAME,
VEN_CONTACT_LAST_NAME VEN_CONTACT_LAST_NAME,
VEN_ADDRESS_LINE_1 VEN_ADDRESS_LINE_1,
VEN_ADDRESS_LINE_2 VEN_ADDRESS_LINE_2,
VEN_CITY VEN_CITY,
VEN_CNT_COUNTY_CODE VEN_CNT_COUNTY_CODE,
VEN_STC_STATE_CODE VEN_STC_STATE_CODE,
VEN_ZIP_CODE VEN_ZIP_CODE,
VEN_PHONE_NO_1 VEN_PHONE_NO_1,
VEN_PHONE_EXTN_1 VEN_PHONE_EXTN_1,
VEN_PHONE_NO_2 VEN_PHONE_NO_2,
VEN_PHONE_EXTN_2 VEN_PHONE_EXTN_2,
VEN_FAX_NO_1 VEN_FAX_NO_1,
VEN_VENDOR_NO VEN_VENDOR_NO,
VEN_APV_AP_VENDOR_ID VEN_APV_AP_VENDOR_ID,
VEN_EMAIL_ADDRESS VEN_EMAIL_ADDRESS,
--all these should be null
to_number(NULL) PHY_LCN_PARAMETER_ID,
to_char(NULL) PHY_LCN_CURRENT_ADDRESS_IND,
to_char(NULL) PHY_LCN_STATUS_CODE,
to_char(NULL) PHY_LCN_LTY_LOCATION_TYPE,
to_char(NULL) PHY_LCN_ADT_ADDRESS_TYPE,
to_char(NULL) PHY_LCN_HOUSE_NO,
to_char(NULL) PHY_LCN_ADDRESS_LINE_1,
to_char(NULL) PHY_LCN_ADDRESS_LINE_2,
to_char(NULL) PHY_LCN_CITY,
to_char(NULL) PHY_LCN_STC_STATE_CODE,
to_char(NULL) PHY_LCN_ZIP_CODE,
to_char(NULL) PHY_LCN_CNT_COUNTY_CODE,
to_date(NULL) PHY_END_DATE,
to_number(NULL) PHY_LCN_VEN_VENDOR_ID_GTA,
to_char(NULL) PHY_LCN_SUB_LOCATION_GTA,
to_char(NULL) PHY_LCN_DIRECTION_GTA,
---all these should be null
to_char(NULL) LOW_LCN_PARAMETER_ID,
to_char(NULL) LOW_LCN_CURRENT_ADDRESS_IND,
to_char(NULL) LOW_LCN_STATUS_CODE,
to_char(NULL) LOW_LCN_LTY_LOCATION_TYPE,
to_char(NULL) LOW_LCN_ADT_ADDRESS_TYPE,
to_char(NULL) LOW_LCN_HOUSE_NO,
to_char(NULL) LOW_LCN_ADDRESS_LINE_1,
to_char(NULL) LOW_LCN_ADDRESS_LINE_2,
to_char(NULL) LOW_LCN_CITY,
to_char(NULL) LOW_LCN_STC_STATE_CODE,
to_char(NULL) LOW_LCN_ZIP_CODE,
to_char(NULL) LOW_LCN_CNT_COUNTY_CODE,
to_char(NULL) LOW_LCN_LANDLORD,
to_number(NULL) LOW_LCN_LANDLORD_PHONE,
to_date(NULL) LOW_END_DATE,
to_char(NULL) LOW_LCN_SUB_LOCATION_GTA,
to_char(NULL) LOW_LCN_DIRECTION_GTA
FROM LOCATIONS LOC , VENDORS VEN
WHERE LOC.LCN_VEN_VENDOR_ID_GTA IS NOT NULL
AND LOC.LCN_VEN_VENDOR_ID_GTA = VEN_VENDOR_ID
AND LOC.LCN_LTY_LOCATION_TYPE ='AS'
UNION ALL
SELECT
to_char(NULL) VEN_COMPANY_NAME,
to_char(NULL) VEN_COMPANY_NAME_2,
to_char(NULL) VEN_CONTACT_FIRST_NAME,
to_char(NULL) VEN_CONTACT_MIDDLE_NAME,
to_char(NULL) VEN_CONTACT_LAST_NAME,
to_char(NULL) VEN_ADDRESS_LINE_1,
to_char(NULL) VEN_ADDRESS_LINE_2,
to_char(NULL) VEN_CITY,
to_char(NULL) VEN_CNT_COUNTY_CODE,
to_char(NULL) VEN_STC_STATE_CODE,
to_char(NULL) VEN_ZIP_CODE,
to_number(NULL) VEN_PHONE_NO_1,
to_number(NULL) VEN_PHONE_EXTN_1,
to_number(NULL) VEN_PHONE_NO_2,
to_number(NULL) VEN_PHONE_EXTN_2,
to_number(NULL) VEN_FAX_NO_1,
to_char(NULL) VEN_VENDOR_NO,
to_char(NULL) VEN_APV_AP_VENDOR_ID,
to_char(NULL) VEN_EMAIL_ADDRESS,
decode(lcn_adt_address_type,'P',to_number(LCN_PARAMETER_ID),to_number(NULL)) PHY_LCN_PARAMETER_ID,
decode(lcn_adt_address_type,'P',LCN_CURRENT_ADDRESS_IND,to_char(NULL)) PHY_LCN_CURRENT_ADDRESS_IND,
decode(lcn_adt_address_type,'P',LCN_STATUS_CODE,to_char(NULL)) PHY_LCN_STATUS_CODE,
decode(lcn_adt_address_type,'P',LCN_STATUS_CODE,to_char(NULL)) PHY_LCN_LTY_LOCATION_TYPE,
decode(lcn_adt_address_type,'P',LCN_ADT_ADDRESS_TYPE,to_char(NULL)) PHY_LCN_ADT_ADDRESS_TYPE,
decode(lcn_adt_address_type,'P',LCN_HOUSE_NO,to_char(NULL)) PHY_LCN_HOUSE_NO,
decode(lcn_adt_address_type,'P',LCN_ADDRESS_LINE_1,to_char(NULL)) PHY_LCN_ADDRESS_LINE_1,
decode(lcn_adt_address_type,'P',LCN_ADDRESS_LINE_2,to_char(NULL)) PHY_LCN_ADDRESS_LINE_2,
decode(lcn_adt_address_type,'P',LCN_CITY,to_char(NULL)) PHY_LCN_CITY,
decode(lcn_adt_address_type,'P',LCN_STC_STATE_CODE,to_char(NULL)) PHY_LCN_STC_STATE_CODE,
decode(lcn_adt_address_type,'P',LCN_ZIP_CODE,to_char(NULL)) PHY_LCN_ZIP_CODE,
decode(lcn_adt_address_type,'P',LCN_CNT_COUNTY_CODE,to_char(NULL)) PHY_LCN_CNT_COUNTY_CODE,
decode(lcn_adt_address_type,'P',END_DATE,to_char(NULL)) PHY_END_DATE,
decode(lcn_adt_address_type,'P',LCN_VEN_VENDOR_ID_GTA,to_char(NULL)) PHY_LCN_VEN_VENDOR_ID_GTA,
decode(lcn_adt_address_type,'P',LCN_SUB_LOCATION_GTA,to_char(NULL)) PHY_LCN_SUB_LOCATION_GTA,
decode(lcn_adt_address_type,'P',LCN_DIRECTION_GTA,to_char(NULL)) PHY_LCN_DIRECTION_GTA,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_PARAMETER_ID,to_char(NULL)) LOW_LCN_PARAMETER_ID,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CURRENT_ADDRESS_IND,to_char(NULL)) LOW_LCN_CURRENT_ADDRESS_IND,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_STATUS_CODE,to_char(NULL)) LOW_LCN_STATUS_CODE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LTY_LOCATION_TYPE,to_char(NULL)) LOW_LCN_LTY_LOCATION_TYPE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADT_ADDRESS_TYPE,to_char(NULL)) LOW_LCN_ADT_ADDRESS_TYPE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_HOUSE_NO,to_char(NULL)) LOW_LCN_HOUSE_NO,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADDRESS_LINE_1,to_char(NULL)) LOW_LCN_ADDRESS_LINE_1,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ADDRESS_LINE_2,to_char(NULL)) LOW_LCN_ADDRESS_LINE_2,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CITY,to_char(NULL)) LOW_LCN_CITY,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_STC_STATE_CODE,to_char(NULL)) LOW_LCN_STC_STATE_CODE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_ZIP_CODE,to_char(NULL)) LOW_LCN_ZIP_CODE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_CNT_COUNTY_CODE,to_char(NULL)) LOW_LCN_CNT_COUNTY_CODE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LANDLORD,to_char(NULL)) LOW_LCN_LANDLORD,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_LANDLORD_PHONE,to_char(NULL)) LOW_LCN_LANDLORD_PHONE,
decode(LCN_ADT_ADDRESS_TYPE,'D',END_DATE,to_char(NULL)) LOW_END_DATE,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_SUB_LOCATION_GTA,to_char(NULL)) LOW_LCN_SUB_LOCATION_GTA,
decode(LCN_ADT_ADDRESS_TYPE,'D',LCN_DIRECTION_GTA,to_char(NULL)) LOW_LCN_DIRECTION_GTA
FROM LOCATIONS LOC
WHERE (LCN_LTY_LOCATION_TYPE ='AS' OR LCN_ADT_ADDRESS_TYPE='D')
AND LCN_CURRENT_ADDRESS_IND ='Y'
thanks -
Flatten rows into a single row
Hi All,
I have a table1 with records and PK for table 1 is (Date,Time).
All I have to do is for a particular transaction, I have to get all the records and flatten them into a single row.
For ex: Table 1 has the following
Date Time Col1 Value
08/03/2010 10:00am Employee_name John
08/03/2010 10:00am Employee_ID 20
08/03/2010 10:00am Salary 10000
Now I have a table 2 which has the following structure:
Date Time Employee_name Employee_ID Salary
08/03/2010 10:00am John 20 10000
Please let me know how to achieve this.,
Thank You.Hi,
Are you saying that you want to create table2, given table1?
Displaying one column from many rows as if they were many columns on one row is called a Pivot , and here's one way to do it:
SELECT date_time
, MIN (CASE WHEN col1 = 'Employee_name' THEN value END) AS employee_name
, MIN (CASE WHEN col1 = 'Employee_ID' THEN value END) AS employee_id
, MIN (CASE WHEN col1 = 'Salary' THEN value END) AS salary
FROM table1
GROUP BY date_time
;Whenever you have a question, say what version of Oracle you're using.
The query above works in Oracle 8.1 and up, but it might be simpler using the SELECT ... PIVOT feature that was introduced in Oracle 11.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements), and also post the results you want from that data. -
Merging Multiple Rows into a single Row
I've read a number of posts with no real good answers or answers that might be good for tables with 3 columns of data. I have a table with 33 columns that will all need to be combined. A little history. Apparently in production the Primary Key Constraint
was dropped which allowed some duplicate data into the table. Now they want me to squish the records together to fix it.
Sorry I couldn't include the screen shot of the data, MSDN says my account isn't verified...
My requirements when I'm putting them together, CERElibilityID is a unique column. This is a sticky problem because in the related tables it is only one of the parent records gets child records related to it.
I just want to keep the one that has the child records in CERPrepActivity table. If there are no child records then the rule will be like all the other records with data.
If a field is null and another record has data we take the record that has data.
If multiple records have data we take the record that has the highest "ModifiedOn" timestamp column value.
I feel like I'm asking a lot, but I'm in a bit of a bind and I've spent the morning Googling and have come up with nothing
Thank you for any help the community can provide and the more specific you can be the better. I'm not a DBA or SQL guru by any stretch so I'm way out of my element.
ThanksUsing the systables, you can get information about your table. I put these together:
SELECT '
LEFT OUTER JOIN #CEREligibility ['+c.name+']
ON s.caseID = ['+c.name+'].caseID
AND s.modifiedOn = ['+c.name+'].modifiedOn
AND ['+c.name+'].['+c.name+'] = (SELECT TOP 1 ['+c.name+'] FROM #CEREligibility WHERE caseID = s.caseID AND ['+c.name+'] IS NOT NULL ORDER BY ModifiedOn)
AND ['+c.name+'].['+c.name+'] IS NOT NULL'
FROM tempdb.sys.objects o
INNER JOIN tempdb.sys.columns c
ON o.object_id = c.object_id
AND o.name LIKE '#CEREligibility%'
SELECT '['+c.name+'].['+c.name+'] AS ['+c.name+'], '
FROM tempdb.sys.objects o
INNER JOIN tempdb.sys.columns c
ON o.object_id = c.object_id
AND o.name LIKE '#CEREligibility%'
On my test system I created your table as a temp table named #CEREligibility.
The first of these two queries generates LEFT OUT JOIN SQL for a self join. Because we're using the columns systable, a LOJ for each column is generated.
The second, produces a select list.
Putting the two together like so, and adding a FROM and GROUP BY gives us:
SELECT
MAX([CEREligibilityId].[CEREligibilityId]) AS [CEREligibilityId], s.[CaseId], MAX([M2Eligibility].[M2Eligibility]) AS [M2Eligibility], MAX([CDREligibility].[CDREligibility]) AS [CDREligibility], MAX([M2Comments].[M2Comments]) AS [M2Comments], MAX([M2CommentsRtf].[M2CommentsRtf]) AS [M2CommentsRtf], MAX([CDRComments].[CDRComments]) AS [CDRComments], MAX([CDRCommentsRtf].[CDRCommentsRtf]) AS [CDRCommentsRtf], MAX([RIAWA].[RIAWA]) AS [RIAWA], MAX([RIAWADate].[RIAWADate]) AS [RIAWADate], MAX([EducationAndTraining].[EducationAndTraining]) AS [EducationAndTraining], MAX([EducationAndTrainingDate].[EducationAndTrainingDate]) AS [EducationAndTrainingDate], MAX([Internship].[Internship]) AS [Internship], MAX([InternshipDate].[InternshipDate]) AS [InternshipDate], MAX([Apprenticeship].[Apprenticeship]) AS [Apprenticeship], MAX([ApprenticeshipDate].[ApprenticeshipDate]) AS [ApprenticeshipDate], MAX([Entrepreneurship].[Entrepreneurship]) AS [Entrepreneurship], MAX([EntrepreneurshipDate].[EntrepreneurshipDate]) AS [EntrepreneurshipDate], MAX([EmploymentPrep].[EmploymentPrep]) AS [EmploymentPrep], MAX([EmploymentPrepDate].[EmploymentPrepDate]) AS [EmploymentPrepDate], MAX([OTPrep].[OTPrep]) AS [OTPrep], MAX([OTPrepDate].[OTPrepDate]) AS [OTPrepDate], MAX([ExitInterview].[ExitInterview]) AS [ExitInterview], MAX([ExitInterviewDate].[ExitInterviewDate]) AS [ExitInterviewDate], MAX([CreatedOn].[CreatedOn]) AS [CreatedOn], MAX([CreatedBy].[CreatedBy]) AS [CreatedBy], MAX([ModifiedOn].[ModifiedOn]) AS [ModifiedOn], MAX([ModifiedBy].[ModifiedBy]) AS [ModifiedBy], MAX([BCPermInEligibility].[BCPermInEligibility]) AS [BCPermInEligibility], MAX([CCPermInEligibility].[CCPermInEligibility]) AS [CCPermInEligibility], MAX([M2EligibilityDate].[M2EligibilityDate]) AS [M2EligibilityDate], MAX([CDREligibilityDate].[CDREligibilityDate]) AS [CDREligibilityDate], MAX([ExitSeparationCode].[ExitSeparationCode]) AS [ExitSeparationCode], MAX([ExitSeparationSubCode].[ExitSeparationSubCode]) AS [ExitSeparationSubCode]
FROM #CEREligibility s
LEFT OUTER JOIN #CEREligibility [CEREligibilityId]
ON s.caseID = [CEREligibilityId].caseID
AND s.modifiedOn = [CEREligibilityId].modifiedOn
AND [CEREligibilityId].[CEREligibilityId] = (SELECT TOP 1 [CEREligibilityId] FROM #CEREligibility WHERE caseID = s.caseID AND [CEREligibilityId] IS NOT NULL ORDER BY ModifiedOn)
AND [CEREligibilityId].[CEREligibilityId] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CaseId]
ON s.caseID = [CaseId].caseID
AND s.modifiedOn = [CaseId].modifiedOn
AND [CaseId].[CaseId] = (SELECT TOP 1 [CaseId] FROM #CEREligibility WHERE caseID = s.caseID AND [CaseId] IS NOT NULL ORDER BY ModifiedOn)
AND [CaseId].[CaseId] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [M2Eligibility]
ON s.caseID = [M2Eligibility].caseID
AND s.modifiedOn = [M2Eligibility].modifiedOn
AND [M2Eligibility].[M2Eligibility] = (SELECT TOP 1 [M2Eligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Eligibility] IS NOT NULL ORDER BY ModifiedOn)
AND [M2Eligibility].[M2Eligibility] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CDREligibility]
ON s.caseID = [CDREligibility].caseID
AND s.modifiedOn = [CDREligibility].modifiedOn
AND [CDREligibility].[CDREligibility] = (SELECT TOP 1 [CDREligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibility] IS NOT NULL ORDER BY ModifiedOn)
AND [CDREligibility].[CDREligibility] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [M2Comments]
ON s.caseID = [M2Comments].caseID
AND s.modifiedOn = [M2Comments].modifiedOn
AND [M2Comments].[M2Comments] = (SELECT TOP 1 [M2Comments] FROM #CEREligibility WHERE caseID = s.caseID AND [M2Comments] IS NOT NULL ORDER BY ModifiedOn)
AND [M2Comments].[M2Comments] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [M2CommentsRtf]
ON s.caseID = [M2CommentsRtf].caseID
AND s.modifiedOn = [M2CommentsRtf].modifiedOn
AND [M2CommentsRtf].[M2CommentsRtf] = (SELECT TOP 1 [M2CommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [M2CommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
AND [M2CommentsRtf].[M2CommentsRtf] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CDRComments]
ON s.caseID = [CDRComments].caseID
AND s.modifiedOn = [CDRComments].modifiedOn
AND [CDRComments].[CDRComments] = (SELECT TOP 1 [CDRComments] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRComments] IS NOT NULL ORDER BY ModifiedOn)
AND [CDRComments].[CDRComments] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CDRCommentsRtf]
ON s.caseID = [CDRCommentsRtf].caseID
AND s.modifiedOn = [CDRCommentsRtf].modifiedOn
AND [CDRCommentsRtf].[CDRCommentsRtf] = (SELECT TOP 1 [CDRCommentsRtf] FROM #CEREligibility WHERE caseID = s.caseID AND [CDRCommentsRtf] IS NOT NULL ORDER BY ModifiedOn)
AND [CDRCommentsRtf].[CDRCommentsRtf] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [RIAWA]
ON s.caseID = [RIAWA].caseID
AND s.modifiedOn = [RIAWA].modifiedOn
AND [RIAWA].[RIAWA] = (SELECT TOP 1 [RIAWA] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWA] IS NOT NULL ORDER BY ModifiedOn)
AND [RIAWA].[RIAWA] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [RIAWADate]
ON s.caseID = [RIAWADate].caseID
AND s.modifiedOn = [RIAWADate].modifiedOn
AND [RIAWADate].[RIAWADate] = (SELECT TOP 1 [RIAWADate] FROM #CEREligibility WHERE caseID = s.caseID AND [RIAWADate] IS NOT NULL ORDER BY ModifiedOn)
AND [RIAWADate].[RIAWADate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EducationAndTraining]
ON s.caseID = [EducationAndTraining].caseID
AND s.modifiedOn = [EducationAndTraining].modifiedOn
AND [EducationAndTraining].[EducationAndTraining] = (SELECT TOP 1 [EducationAndTraining] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTraining] IS NOT NULL ORDER BY ModifiedOn)
AND [EducationAndTraining].[EducationAndTraining] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EducationAndTrainingDate]
ON s.caseID = [EducationAndTrainingDate].caseID
AND s.modifiedOn = [EducationAndTrainingDate].modifiedOn
AND [EducationAndTrainingDate].[EducationAndTrainingDate] = (SELECT TOP 1 [EducationAndTrainingDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EducationAndTrainingDate] IS NOT NULL ORDER BY ModifiedOn)
AND [EducationAndTrainingDate].[EducationAndTrainingDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [Internship]
ON s.caseID = [Internship].caseID
AND s.modifiedOn = [Internship].modifiedOn
AND [Internship].[Internship] = (SELECT TOP 1 [Internship] FROM #CEREligibility WHERE caseID = s.caseID AND [Internship] IS NOT NULL ORDER BY ModifiedOn)
AND [Internship].[Internship] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [InternshipDate]
ON s.caseID = [InternshipDate].caseID
AND s.modifiedOn = [InternshipDate].modifiedOn
AND [InternshipDate].[InternshipDate] = (SELECT TOP 1 [InternshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [InternshipDate] IS NOT NULL ORDER BY ModifiedOn)
AND [InternshipDate].[InternshipDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [Apprenticeship]
ON s.caseID = [Apprenticeship].caseID
AND s.modifiedOn = [Apprenticeship].modifiedOn
AND [Apprenticeship].[Apprenticeship] = (SELECT TOP 1 [Apprenticeship] FROM #CEREligibility WHERE caseID = s.caseID AND [Apprenticeship] IS NOT NULL ORDER BY ModifiedOn)
AND [Apprenticeship].[Apprenticeship] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ApprenticeshipDate]
ON s.caseID = [ApprenticeshipDate].caseID
AND s.modifiedOn = [ApprenticeshipDate].modifiedOn
AND [ApprenticeshipDate].[ApprenticeshipDate] = (SELECT TOP 1 [ApprenticeshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ApprenticeshipDate] IS NOT NULL ORDER BY ModifiedOn)
AND [ApprenticeshipDate].[ApprenticeshipDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [Entrepreneurship]
ON s.caseID = [Entrepreneurship].caseID
AND s.modifiedOn = [Entrepreneurship].modifiedOn
AND [Entrepreneurship].[Entrepreneurship] = (SELECT TOP 1 [Entrepreneurship] FROM #CEREligibility WHERE caseID = s.caseID AND [Entrepreneurship] IS NOT NULL ORDER BY ModifiedOn)
AND [Entrepreneurship].[Entrepreneurship] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EntrepreneurshipDate]
ON s.caseID = [EntrepreneurshipDate].caseID
AND s.modifiedOn = [EntrepreneurshipDate].modifiedOn
AND [EntrepreneurshipDate].[EntrepreneurshipDate] = (SELECT TOP 1 [EntrepreneurshipDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EntrepreneurshipDate] IS NOT NULL ORDER BY ModifiedOn)
AND [EntrepreneurshipDate].[EntrepreneurshipDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EmploymentPrep]
ON s.caseID = [EmploymentPrep].caseID
AND s.modifiedOn = [EmploymentPrep].modifiedOn
AND [EmploymentPrep].[EmploymentPrep] = (SELECT TOP 1 [EmploymentPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrep] IS NOT NULL ORDER BY ModifiedOn)
AND [EmploymentPrep].[EmploymentPrep] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [EmploymentPrepDate]
ON s.caseID = [EmploymentPrepDate].caseID
AND s.modifiedOn = [EmploymentPrepDate].modifiedOn
AND [EmploymentPrepDate].[EmploymentPrepDate] = (SELECT TOP 1 [EmploymentPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [EmploymentPrepDate] IS NOT NULL ORDER BY ModifiedOn)
AND [EmploymentPrepDate].[EmploymentPrepDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [OTPrep]
ON s.caseID = [OTPrep].caseID
AND s.modifiedOn = [OTPrep].modifiedOn
AND [OTPrep].[OTPrep] = (SELECT TOP 1 [OTPrep] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrep] IS NOT NULL ORDER BY ModifiedOn)
AND [OTPrep].[OTPrep] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [OTPrepDate]
ON s.caseID = [OTPrepDate].caseID
AND s.modifiedOn = [OTPrepDate].modifiedOn
AND [OTPrepDate].[OTPrepDate] = (SELECT TOP 1 [OTPrepDate] FROM #CEREligibility WHERE caseID = s.caseID AND [OTPrepDate] IS NOT NULL ORDER BY ModifiedOn)
AND [OTPrepDate].[OTPrepDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ExitInterview]
ON s.caseID = [ExitInterview].caseID
AND s.modifiedOn = [ExitInterview].modifiedOn
AND [ExitInterview].[ExitInterview] = (SELECT TOP 1 [ExitInterview] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterview] IS NOT NULL ORDER BY ModifiedOn)
AND [ExitInterview].[ExitInterview] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ExitInterviewDate]
ON s.caseID = [ExitInterviewDate].caseID
AND s.modifiedOn = [ExitInterviewDate].modifiedOn
AND [ExitInterviewDate].[ExitInterviewDate] = (SELECT TOP 1 [ExitInterviewDate] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitInterviewDate] IS NOT NULL ORDER BY ModifiedOn)
AND [ExitInterviewDate].[ExitInterviewDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CreatedOn]
ON s.caseID = [CreatedOn].caseID
AND s.modifiedOn = [CreatedOn].modifiedOn
AND [CreatedOn].[CreatedOn] = (SELECT TOP 1 [CreatedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedOn] IS NOT NULL ORDER BY ModifiedOn)
AND [CreatedOn].[CreatedOn] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CreatedBy]
ON s.caseID = [CreatedBy].caseID
AND s.modifiedOn = [CreatedBy].modifiedOn
AND [CreatedBy].[CreatedBy] = (SELECT TOP 1 [CreatedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [CreatedBy] IS NOT NULL ORDER BY ModifiedOn)
AND [CreatedBy].[CreatedBy] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ModifiedOn]
ON s.caseID = [ModifiedOn].caseID
AND s.modifiedOn = [ModifiedOn].modifiedOn
AND [ModifiedOn].[ModifiedOn] = (SELECT TOP 1 [ModifiedOn] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedOn] IS NOT NULL ORDER BY ModifiedOn)
AND [ModifiedOn].[ModifiedOn] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ModifiedBy]
ON s.caseID = [ModifiedBy].caseID
AND s.modifiedOn = [ModifiedBy].modifiedOn
AND [ModifiedBy].[ModifiedBy] = (SELECT TOP 1 [ModifiedBy] FROM #CEREligibility WHERE caseID = s.caseID AND [ModifiedBy] IS NOT NULL ORDER BY ModifiedOn)
AND [ModifiedBy].[ModifiedBy] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [BCPermInEligibility]
ON s.caseID = [BCPermInEligibility].caseID
AND s.modifiedOn = [BCPermInEligibility].modifiedOn
AND [BCPermInEligibility].[BCPermInEligibility] = (SELECT TOP 1 [BCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [BCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
AND [BCPermInEligibility].[BCPermInEligibility] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CCPermInEligibility]
ON s.caseID = [CCPermInEligibility].caseID
AND s.modifiedOn = [CCPermInEligibility].modifiedOn
AND [CCPermInEligibility].[CCPermInEligibility] = (SELECT TOP 1 [CCPermInEligibility] FROM #CEREligibility WHERE caseID = s.caseID AND [CCPermInEligibility] IS NOT NULL ORDER BY ModifiedOn)
AND [CCPermInEligibility].[CCPermInEligibility] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [M2EligibilityDate]
ON s.caseID = [M2EligibilityDate].caseID
AND s.modifiedOn = [M2EligibilityDate].modifiedOn
AND [M2EligibilityDate].[M2EligibilityDate] = (SELECT TOP 1 [M2EligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [M2EligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
AND [M2EligibilityDate].[M2EligibilityDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [CDREligibilityDate]
ON s.caseID = [CDREligibilityDate].caseID
AND s.modifiedOn = [CDREligibilityDate].modifiedOn
AND [CDREligibilityDate].[CDREligibilityDate] = (SELECT TOP 1 [CDREligibilityDate] FROM #CEREligibility WHERE caseID = s.caseID AND [CDREligibilityDate] IS NOT NULL ORDER BY ModifiedOn)
AND [CDREligibilityDate].[CDREligibilityDate] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ExitSeparationCode]
ON s.caseID = [ExitSeparationCode].caseID
AND s.modifiedOn = [ExitSeparationCode].modifiedOn
AND [ExitSeparationCode].[ExitSeparationCode] = (SELECT TOP 1 [ExitSeparationCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationCode] IS NOT NULL ORDER BY ModifiedOn)
AND [ExitSeparationCode].[ExitSeparationCode] IS NOT NULL
LEFT OUTER JOIN #CEREligibility [ExitSeparationSubCode]
ON s.caseID = [ExitSeparationSubCode].caseID
AND s.modifiedOn = [ExitSeparationSubCode].modifiedOn
AND [ExitSeparationSubCode].[ExitSeparationSubCode] = (SELECT TOP 1 [ExitSeparationSubCode] FROM #CEREligibility WHERE caseID = s.caseID AND [ExitSeparationSubCode] IS NOT NULL ORDER BY ModifiedOn)
AND [ExitSeparationSubCode].[ExitSeparationSubCode] IS NOT NULL
GROUP BY s.caseID
When I ran this against your test data, It produced a single row for each of the two case ID's.
To keep performance in line, I also created a covering index on the temp table:
CREATE INDEX idx_caseID_ModifiedOn ON #CEREligibility (caseID, modifiedOn) INCLUDE ([CEREligibilityId], [M2Eligibility], [CDREligibility], [M2Comments], [M2CommentsRtf], [CDRComments], [CDRCommentsRtf], [RIAWA], [RIAWADate], [EducationAndTraining], [EducationAndTrainingDate], [Internship], [InternshipDate], [Apprenticeship], [ApprenticeshipDate], [Entrepreneurship], [EntrepreneurshipDate], [EmploymentPrep], [EmploymentPrepDate], [OTPrep], [OTPrepDate], [ExitInterview], [ExitInterviewDate], [CreatedOn], [CreatedBy], [ModifiedBy], [BCPermInEligibility], [CCPermInEligibility], [M2EligibilityDate], [CDREligibilityDate], [ExitSeparationCode], [ExitSeparationSubCode])
Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question. -
Merging two results into a single row
Hi, Everyone... I think this is a weighted question and I feel like it's a bit difficult to phrase, so if it doesn't make sense - let me know and I'll try to clarify or provide some more concrete examples (if I can) :)
I have a few tables inner joined in my sql query - I'd post the entire query here but it's lengthy and will probably add a bit more confusion so let's start with theorizing - where the results sometimes generate more than one row. If more than one row exists, I'd like to take the lowest number in one field and the highest number in another field, and display them on a single row.
For instance, when I join the PERIOD and SCHEDULE tables, the PERIOD table might provide two rows like the following:
SCHEDULE_ID PERIOD_ID START_TIME END_TIME
123 100 32820 35640
123 101 35940 38760My final result should take the lowest START_TIME and the highest END_TIME, even if they exist is separate rows.
START_TIME END_TIME
32820 38760It doesn't seem easy to me so if someone can make sense of this - you deserve an award. :) If I can provide some more clarification, please let me know. Thanks for any help. Oracle 11g
Edited by: nage62587 on Sep 27, 2012 11:32 AMnage62587 wrote:
Thanks! I'll try that... I have more than these columns in the result and I'm thinking a Group By likely wouldn't work - I will try but in the event it doesn't, does anyone else have any other suggestions?Group by is the correct way to do this. You group several rows of output into one row. Then you decide which values from inside that group you want to see. This is certainly possible. There are more aggregation functions available than you might think, not only min/max, also min/max + KEEP, count(case expression) and so on. -
Record Working Time task merging multiple employees into a single task
Hi Everyone,
I'm going to check our configuration again to see if this is standard behaviour, config, or a problem with EHP 3's version of record working time.
So if employee A submits to manager A 1 task is created. Then when employee B submits to manager A we were expecting 2 tasks. However, we've been noticing manager A is getting 1 task with several line times.
We are ok with it merging tasks for employee A over multiple weeks. That is ideal actually.
The problem is that employee B's task should be separate.
Is there a quick fix?
Thanks,
Doug RobbinsI did try 31000007 and noticed the same behavior. Are you saying I should use an older version of the task to get back to grouped by employee number and not merging everything?
Well this causing us issues for a few reasons. The main one we developed a work around because we had to make sure emails were not being sent to 1 person for all the employees with their data. That would cause obvious security concerns.
But when forward tasks out managers want to be able to forward a specific employee's requests and not all of them. If some customers want this it should be a configurable option. To allow companies that want 1 single task or companies that want 1 task/employee/week.
This is inconsistent with the other portal applications. It would be nice if Germany picked 1 way of doing things or provided more configuration options. I'm hoping that OSS gives us something because merging everything into a single task for all employees is not the behaviour we want or expected.
I always appreciate your input because you have been very helpful as I learn about portal.
Thanks,
Doug R
Thanks you -
Mergeing multiple procedures into a single package ???
Hello Gurus,
I m moving the data from the from one schema i,e source(SRC) schema to the another schema i,e target(trg) table, only selected columns of few tables (i,e for 4 tables)
I m writing procedures to accomplish this and put this procedures to a scheduler on a daily basis to load
I m writing 4 procedures one for each of the table .....here is the procedure i have got
create or replace procedure mov_tbl1
is
cursor tbl1_cur as
select src.col1,
src.col2,
src.col3,
src.col4
from source.tbl1 src
where col1 = ' xyz'
tbl1_cur_rec tbl1_cur%rowtype;
begin
for tbl1_cur_rec in tbl1_cur
loop
insert into tgt.tabl1(col1,col2,col3,col4)
values ( tbl1_cur_rec.col1,
tbl1_cur_reccol2,
tbl1_cur_rec.col3,
tbl1_cur_rec.col4);
commit
exception
when others then
rollback;
end loop;
end;
---for table 2
create or replace procedure mov_tbl2
is
cursor tbl2_cur as
select src.col1,
src.col2,
src.col3,
src.col4
from source.tbl2 src
where col3 = ' abc'
tbl2_cur_rec tbl2_cur%rowtype;
begin
for tbl2_cur_rec in tbl2_cur
loop
insert into tgt.table2(col1,col2,col3,col4)
values ( tbl2_cur_rec.col1,
tbl2_cur_reccol2,
tbl2_cur_rec.col3,
tbl2_cur_rec.col4);
commit
exception
when others then
rollback;
end loop;
end;
similarly procedures for table 3 and table 4....
here is my question....
1.How can i build a single package for all these four procedures in one package ???
2. ANd i don't want to call each procedure every time ...so can i do it by passing parameters ??? how can i accomplish that ??
I m new to writing packages ....any help is greatly appriciated ....Thank you so much gurus!!!!First of all your code doesn't compile because the exception block is inside the loop while begin and end are outside.
You have to decide whether a single row error has to invalidate the full load or if the single wrong row has to be rejected but all the other rows have to be loaded.
I suppose you need the latter hence I'm changing the code as follows:
create or replace procedure mov_tbl1
is
cursor tbl1_cur as
select src.col1,
src.col2,
src.col3,
src.col4
from source.tbl1 src
where col1 = ' xyz'
-- the record variable declaration is implicit in FOR LOOP
begin
for tbl1_cur_rec in tbl1_cur
loop
begin
insert into tgt.tabl1(col1,col2,col3,col4)
values ( tbl1_cur_rec.col1,
tbl1_cur_reccol2,
tbl1_cur_rec.col3,
tbl1_cur_rec.col4);
-- REMOVED COMMIT, Commit outside or at the end.
exception
when others then
null; -- May be is better to (somehow) log the error ...
end;
end loop;
end;About the package, you create it this way:
create or replace package p is
procedure upd (tab1 in boolean, tab2 in boolean, tab3 in boolean, tab4 in boolean);
end;
create or replace package p is
procedure upd (tab1 in boolean, tab2 in boolean, tab3 in boolean, tab4 in boolean) is
begin
if tab1=true then
mov_tbl1;
end if;
if tab2=true then
mov_tbl2;
end if;
if tab2=true then
mov_tbl2;
end if;
if tab2=true then
mov_tbl2;
end if;
end;
procedure mov_tbl1 is
cursor tbl1_cur as
select src.col1,
src.col2,
src.col3,
src.col4
from source.tbl1 src
where col1 = ' xyz'
-- the record variable declaration is implicit in FOR LOOP
begin
for tbl1_cur_rec in tbl1_cur
loop
begin
insert into tgt.tabl1(col1,col2,col3,col4)
values ( tbl1_cur_rec.col1,
tbl1_cur_reccol2,
tbl1_cur_rec.col3,
tbl1_cur_rec.col4);
-- REMOVED COMMIT, Commit outside or at the end.
exception
when others then
null; -- May be is better to (somehow) log the error ...
end;
end loop;
end;
procedure mov_tbl2 is ...
procedure mov_tbl3 is ...
procedure mov_tbl4 is ...
end;
/You can call the upd procedure (that calls the others) this way:
begin
p.upd(true,false,true,false);
end;
/To update only table1 and table3.
Max
http://oracleitalia.wordpress.com -
Which product should I use to merge multiple PDFs into a single PDF?
Hi. Discussion title pretty much says it all. I have many existing pdf files which I would like to merge into a single multipage pdf document. Can I actually do that? Am I limited by size? Which product works best?
Thanks in advance for any advice.
~mdsHi mds42,
You can combine PDF files with Acrobat as well as with 'Combine files' feature in 'PDF Pack'.
For Acrobat kindly refer this link:Merge PDF files into one, merging files to PDF | Adobe Acrobat XI
Via PDF Pack/Reader refer:Using Adobe PDF Pack
https://acrobatusers.com/tutorials/how-to-combine-pdf-files-using-adobe-reader
Regards,
Florence -
select OPRCLASS,BUSINESS_UNIT from ps_sec_bu_cls where oprclass like 'OHRL_ADA01%';
OPRCLASS BUSINESS_UNIT
OHRL_ADA01 ADA01
OHRL_ADA01 PRT01
OHRL_ADA01 STATE
How can i merge all the BUSINESS_UNIT rows into one row with a delimiter?
OPRCLASS BUSINESS_UNIT
OHRL_ADA01 ADA01, PRT01, STATEOne possible solution: STRAGG
-
Need help with turning multiple rows into a single row
Hello.
I've come across a situation that is somewhat beyond my knowledge base. I could use a little help with figuring this out.
My situation:
I am attempting to do some reporting from a JIRA database. What I am doing is getting the dates and times for specific step points of a ticket. This is resulting in many rows per ticket. What I need to do is return one row per ticket with a calculation of time between each step. But one issue is that if a ticket is re-opened, I want to ignore all data beyond the first close date. Also, not all tickets are in a closed state. I am attaching code and a sample list of the results. If I am not quite clear, please ask for information and I will attempt to provide more. The database is 10.2.0.4
select jiraissue.id, pkey, reporter, summary
,changegroup.created change_dt
,dbms_lob.substr(changeitem.newstring,15,1) change_type
,row_number() OVER ( PARTITION BY jiraissue.id ORDER BY changegroup.created ASC ) AS order_row
from jiraissue
,changeitem, changegroup
,(select * from customfieldvalue where customfield = 10591 and stringvalue = 'Support') phaseinfo
where jiraissue.project = 10110
and jiraissue.issuetype = 51
and dbms_lob.substr(changeitem.newstring,15,1) in ('Blocked','Closed','Testing','Open')
and phaseinfo.issue = jiraissue.id
and changeitem.groupid = changegroup.id
and changegroup.issueid = jiraissue.id
order by jiraissue.id,change_dt
Results:
1 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2008-07-16 9:30:38 AM Open 1
2 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2008-07-16 11:37:02 AM Testing 2
3 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-06-08 9:14:52 AM Closed 3
4 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-09-02 11:29:37 AM Open 4
5 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-09-02 11:29:42 AM Open 5
6 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-09-02 11:29:50 AM Testing 6
7 21191 QCS-91 Error running the Earliest-deadlines flight interface request/response message 2010-09-02 11:29:53 AM Closed 7
8 23234 QCS-208 System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role 2008-10-03 10:26:21 AM Open 1
9 23234 QCS-208 System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role 2008-11-17 9:39:39 AM Testing 2
10 23234 QCS-208 System Baseline - OK button does not show up in the Defer Faults page for the System Engineer role 2011-02-02 6:18:02 AM Closed 3
11 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2008-09-29 2:44:54 PM Open 1
12 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2010-05-29 4:47:37 PM Blocked 2
13 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2011-02-02 6:14:57 AM Open 3
14 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2011-02-02 6:15:32 AM Testing 4
15 23977 QCS-311 Tally Sheet - Reason Not Done fails to provide reason for unassigned tasks 2011-02-02 6:15:47 AM Closed 5Hi,
Welcome to the forum!
StblJmpr wrote:
... I am attempting to do some reporting from a JIRA database. What is a JIRA database?
I am attaching code and a sample list of the results. If I am not quite clear, please ask for information and I will attempt to provide more. Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and the results you want from that data.
Simplify the problem as much as possible. For example, if the part you don't know how to do only involves 2 tables, then jsut post a question involving those 2 tables. So you might just post this much data:
CREATE TABLE changegroup
( issueid NUMBER
, created DATE
, id NUMBER
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2008-07-16 09:30:38 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2008-07-16 11:37:02 AM', 'YYYY-MM-DD HH:MI:SS AM'), 20);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-06-08 09:14:52 AM', 'YYYY-MM-DD HH:MI:SS AM'), 90);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-09-02 11:29:37 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-09-02 11:29:42 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-09-02 11:29:50 AM', 'YYYY-MM-DD HH:MI:SS AM'), 20);
INSERT INTO changegroup (issueid, created, id) VALUES (21191, TO_DATE ('2010-09-02 11:29:53 AM', 'YYYY-MM-DD HH:MI:SS AM'), 90);
INSERT INTO changegroup (issueid, created, id) VALUES (23234, TO_DATE ('2008-10-03 10:26:21 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (23234, TO_DATE ('2008-11-17 09:39:39 AM', 'YYYY-MM-DD HH:MI:SS AM'), 20);
INSERT INTO changegroup (issueid, created, id) VALUES (23234, TO_DATE ('2011-02-02 06:18:02 AM', 'YYYY-MM-DD HH:MI:SS AM'), 90);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2008-09-29 02:44:54 PM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2010-05-29 04:47:37 PM', 'YYYY-MM-DD HH:MI:SS AM'), 30);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2011-02-02 06:14:57 AM', 'YYYY-MM-DD HH:MI:SS AM'), 10);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2011-02-02 06:15:32 AM', 'YYYY-MM-DD HH:MI:SS AM'), 20);
INSERT INTO changegroup (issueid, created, id) VALUES (23977, TO_DATE ('2011-02-02 06:15:47 AM', 'YYYY-MM-DD HH:MI:SS AM'), 90);
CREATE TABLE changeitem
( groupid NUMBER
, newstring VARCHAR2 (10)
INSERT INTO changeitem (groupid, newstring) VALUES (10, 'Open');
INSERT INTO changeitem (groupid, newstring) VALUES (20, 'Testing');
INSERT INTO changeitem (groupid, newstring) VALUES (30, 'Blocked');
INSERT INTO changeitem (groupid, newstring) VALUES (90, 'Closed');Then post the results you want to get from that data, like this:
ISSUEID HISTORY
21191 Open (0) >> Testing (692) >> Closed
23234 Open (45) >> Testing (807) >> Closed
23977 Open (607) >> Blocked (249) >> Open (0) >> Testing (0) >> ClosedExplain how you get those results from that data. For example:
"The output contains one row per issueid. The HISTORY coloumn shows the different states that the issue went through, in order by created, starting with the earliest one and continuing up until the first 'Closed' state, if there is one. Take the first row, issueid=21191, for example. It started as 'Open' on July 16, 2008, then, on the same day (that is, 0 days later) changed to 'Testing', and then, on June 8, 2010, (692 days later), it became 'Closed'. That same issue opened again later, on September 2, 2010, but I don't want to see any activity after the first 'Closed'."
The database is 10.2.0.4That's very important. Always post your version, like you did.
Here's one way to get those results from that data:
WITH got_order_row AS
SELECT cg.issueid
, LEAD (cg.created) OVER ( PARTITION BY cg.issueid
ORDER BY cg.created
- cg.created AS days_in_stage
, ROW_NUMBER () OVER ( PARTITION BY cg.issueid
ORDER BY cg.created
) AS order_row
, ci.newstring AS change_type
FROM changegroup cg
JOIN changeitem ci ON cg.id = ci.groupid
WHERE ci.newstring IN ( 'Blocked'
, 'Closed'
, 'Testing'
, 'Open'
-- AND ... -- any other filtering goes here
SELECT issueid
, SUBSTR ( SYS_CONNECT_BY_PATH ( change_type || CASE
WHEN CONNECT_BY_ISLEAF = 0
THEN ' ('
|| ROUND (days_in_stage)
|| ')'
END
, ' >> '
, 5
) AS history
FROM got_order_row
WHERE CONNECT_BY_ISLEAF = 1
START WITH order_row = 1
CONNECT BY order_row = PRIOR order_row + 1
AND issueid = PRIOR issueid
AND PRIOR change_type != 'Closed'
ORDER BY issueid
;Combining data from several rows into one big delimited VARCHAR2 column on one row is call String Aggregation .
I hope this answers your question, but I guessed at so many things, I won't be surprised if it doesn't. If that's the case, point out where this is wrong, post what the results should be in those places, and explain how you get those results. Post new data, if necessary. -
Multiple rows into a single row.
Table structure:
CREATE TABLE JOB_ERROR_MESSAGE_TMP
ERROR_LOG VARCHAR2(1000 BYTE)
This table gets populated with multiple records (approx 20) from the log file of my application.
Example of Data (12 rows below):
ERROR_LOG
XXXXXXXX(Error)-ORA-01756-ZZZZZZZZZZZZZ-quoted string not properly terminated
line1 of error1
line2 of error1
line3 of error1
XXXXXXXX(Error)-DBS-0000-ZZZZZZZZZZZZZ-SOME ERROR
line1 of error2
line2 of error2
XXXXXXXX(Error)-DBS-1111-ZZZZZZZZZZZZZ-SOME NEW ERROR
line1 of error3
line2 of error3
line2 of error4
line4 of error3
I am interested in only the first error. That is: all the rows until the second occurrence of word "(ERROR)"
Desired output:
ORA-01756,quoted string not properly terminated,line1 of error1,line2 of error1,line3 of error1
That is:
The 9 digit code which exists after the 1st encounter of word '(Error)'||','||trim(First line after error)||','||trim(second line after error)||','||
trim of 3rd line <all the lines untill the line containing '(ERROR)' is encountered>
Any help on this is appreciated.
Thanks in advance
CoolguyExample...
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as ord, 'XXXXXXXX(Error)-ORA-01756-ZZZZZZZZZZZZZ-quoted string not properly terminated' as txt from dual union all
2 select 2, 'line1 of error1' from dual union all
3 select 3, 'line2 of error1' from dual union all
4 select 4, 'line3 of error1' from dual union all
5 select 5, 'XXXXXXXX(Error)-DBS-0000-ZZZZZZZZZZZZZ-SOME ERROR' from dual union all
6 select 6, 'line1 of error2' from dual union all
7 select 7, 'line2 of error2' from dual union all
8 select 8, 'XXXXXXXX(Error)-DBS-1111-ZZZZZZZZZZZZZ-SOME NEW ERROR' from dual union all
9 select 9, 'line1 of error3' from dual union all
10 select 10, 'line2 of error3' from dual union all
11 select 11, 'line2 of error4' from dual union all
12 select 12, 'line4 of error3' from dual)
13 -- end of test data
14 select txt
15 from (
16 select ord, txt, starter, lag(starter) over (order by ord) as prev
17 from (
18 select ord, txt, decode(instr(txt,'(Error)'),0,null,1) as starter
19 from t
20 order by ord
21 )
22 )
23 where coalesce(starter, prev) = 1
24* order by ord
SQL> /
TXT
XXXXXXXX(Error)-ORA-01756-ZZZZZZZZZZZZZ-quoted string not properly terminated
line1 of error1
XXXXXXXX(Error)-DBS-0000-ZZZZZZZZZZZZZ-SOME ERROR
line1 of error2
XXXXXXXX(Error)-DBS-1111-ZZZZZZZZZZZZZ-SOME NEW ERROR
line1 of error3
6 rows selected.
SQL>Your problem is going to be that you haven't got anything in your table which specifies the order of the rows. As such you have an unordered set of data in a table and there is nothing to say which rows of data are associated with other rows. If you want it to work you're going to have to update your table to include a sequence number or a date/timestamp. -
Combining multiple rows into a single row
Hi all,
I have a tricky situation in a HR select.
Imagine I have a dataset as below, simplified of course.
Name Start Date End date Job Title Salary
Tom 01/01/07 02/03/08 Gopher £500
Tom 03/03/08 jobsworth £600
Rick 04/05/09 Painter £500
Harry 02/06/07 02/06/08 Gardener £300
Harry 03/06/08 03/06/09 Runner £200
Harry 04/06/09 Cook £400
now, I need to select from above and return 3 rows so it looks as below
name start date enddate title salary start date enddate title salary start date enddate title salary etc etc
tom 01/01/07 02/03/08 gopher £500 03/03/08 blah 600
Rick 04/05/09 painter £500
harry etc etc etc
Now, I know how to select onto one row ok, asumming that each employee has a fixed number of roles but the problem is that each employee has a different number of jobs, one could have had 5 while another 50 and I do not know the maximum at this time.
Anyone have any ideas on how to appraoch this?
tia,
dw
Edited by: derrywriter on Oct 2, 2009 3:50 PM
Edited by: derrywriter on Oct 2, 2009 3:54 PMIdeally this should be done in a suitable reporting tool.
Standard SQL requires a deterministic number of columns to be known at parse time i.e. before the data is fetched it needs to know how many columns are being returned.
If you know there is a fixed maximum to the number of columns that can be returned you can use one of the various pivot methods (search the forum) which differ depending on whether you're using 9i, 10g or 11g database.
If you can't determine a maximum number of columns you're pretty much stuck, unless you want to write some clever interfacing to the oracle ODCI as demonstrated in this thread:
How to pipeline a function with a dynamic number of columns?
Personally, I believe such reporting styles should be reserved for reporting tools. -
Convert multiple rows into a single row
Hi friends..
I have a table with the following information
SQL> select * from tsting;
A B C D E
10
10
10
29-MAY-09
TESTBut I need the following result..
A B C D E
10 10 10 29-MAY-09 TESTHello,
Try:
WITH test_data AS (
SELECT 10 A, NULL B, NULL C, NULL D, NULL E FROM DUAL UNION ALL
SELECT NULL A, 10 B, NULL C, NULL D, NULL E FROM DUAL UNION ALL
SELECT NULL A, NULL B, 10 C, NULL D, NULL E FROM DUAL UNION ALL
SELECT NULL A, NULL B, NULL C, TO_DATE('29-MAY-09','DD-MON-YY') D, NULL E FROM DUAL UNION ALL
SELECT NULL A, NULL B, NULL C, NULL D, 'TEST' E FROM DUAL)
-- end test data
SELECT MAX(A) A, MAX(B) B, MAX(C) C, MAX(D) D, MAX(E) E
FROM test_data;
A B C D E
10 10 10 29-MAY-09 TEST -
Insert data from two rows into a single row in a new table
Hi
i have a table like the following
Deptno Dname Salary
10 Computer 2000
10 Computer 4000
10 Computer 3000
10 Science 6000
10 Science 1000
10 Science 4000
10 Science 10000
I want to insert data into a new table like the following
Deptno MaxSalCom Minsalcom MinSalSci MaxSaSci
10 2000 4000 1000 10000
Deptno--As in Table1
MaxSalCom--Maximum salary for Dname " Computer"
Minsalcom--Minimum salary for Dname " Computer"
MaxSalSci--Maximum salary for Dname " Science"
MinsalSci--Minimum salary for Dname " Science"
Please help me how to go about itwith data as
(select 10 dno, 'Computer' dname, 2000 sal FROM dual
union all
select 10, 'Computer', 4000 FROM dual
union all
select 10, 'Computer', 3000 FROM dual
UNION all
select 10, 'Science', 6000 FROM dual
union all
select 10, 'Science', 1000 FROM dual
union all
select 10, 'Science', 4000 FROM dual
union all
select 10, 'Science', 10000 FROM dual
select dno, min(decode(dname,'Computer',sal)) min_sal_comp , max(decode(dname,'Computer',sal)) max_sal_comp,
min(decode(dname,'Science',sal))min_sal_sci , max(decode(dname,'Science',sal)) max_sal_sci
from data
group by dno;
Maybe you are looking for
-
Battery drain after downloading free apps BUT never launched them
I have searched all 7 pages of iPhone 3G section, any topic with "battery" in subject line, did not find a match, so posting new question. I'm a new 3G owner; use wifi and bluetooth, fetch mail manually (no push); battery life easily holds 2-3 days w
-
New Parameter As Of Date (Period) In Invoice Aging Report Doc ID:752120.1
Hi Hussein, EBS R12 (12.0.6) Rhel 4.6 How do I apply this kind of patch? Solution This is Enhancement Request 70091 ADD PARAMETER TO RUN INVOICE AGING REPORT AS OF A CERTAIN DATE Thanks a lot
-
I just purchased 2 Apple TVs and a new iMac computer. I have about 400 DVD movies that I would like to copy to the iMac so I can stream them to the Apple TVs. I also would like to have the cover art and movie description like you get with movies purc
-
Audio files currently Mobile.me hosted - how to move to iCloud?
We need to transfer hundreds of spoken word audio files (aac and mp3), from mobile.me hosting. Here is an example of where one of these files resides –- http://web.me.com/mehermontessori/MandaliHallTalks/eruchtalks/Eruch_August1_1987 /MP3Aug1_1987/Ja
-
Don't Start the dispatcher after Error in Upgrade of SQL2000 to SQL 2005
HI, We have a problem after try to upgrade the SQL 2000 to SQL2005.We have two SID in one server, the upgrade of the first that perfect, but when we try to do the same to the other in SAPINST of SAPTOOLS stopped in theproccess when create the storad