Report to concatenate several lines into one line

I have three tables:
1 project Pk = proj_id
2 Resources_on_Project Pk = Resources_on_proj_id Foreign_key = proj_id
3 cost Pk = cost_id Foreign_key = proj_id

columns in the table:

Project: proj_id, proj_name, proj_description
Resources_on_Project: Resources_on_proj_id, proj_id, id_ressource
cost: cost_id, proj_id, cost_type, cost_incurred

the table relationships:

Project: Resources_on_project 1:m (project has several resources in Appendix)
Cost of the project: 1:m (project has many costs in annex)

Data:

Project:
PROJ_ID, proj_name, proj_description
1, CDM, Advisory Services

2, efficient lighting, efficient ESCO

Resources_on_project
Resources_on_proj_id, proj_id, id_ressource
1, 1, 1
2, 1, 2
3, 2, 3
4, 2, 4

Cost:
cost_id proj_id cost_type cost_incurred
1.1, food, 1200
2.1, travel, 2000
3.1, trip, 3500
4.1 food, 1200
5.1, trip, 1400
6.1, travel, 1200
7,2 trip, 2000
8.2 food, 1200
9.2, trip, 1300
10.2, food, 2000
11.2, travel, 800
12.2, travel, 1150
13.2, food, 3000
14.2, food, 1000
15.2, food, 2400


First project has 2 resources attached to it and 6 different costs.
Second project includes 2 resources and 9 heads of different costs.

I want a report that gives me:

Proj_name, Proj_description, id_ressource, cost_incurred
Advisory services CDM 10500 1/2

ESCO effective effective lighting 14850 3/4


I wrote a query:
«Select «PROJECT»» PROJ_NAME' as 'PROJ_NAME. "
««PROJECT»» PROJ_DESCRIPTION' as 'PROJ_DESCRIPTION. "
sum (COST. COST_INCURRED) as "COST_INCURRED."
'RESOURCES_ON_PROJECTS '. "" RESOURCE_ID ' as 'RESOURCE_ID.
'COST', 'cost ',.
"RESOURCES_ON_PROJECTS" "RESOURCES_ON_PROJECTS"
'PROJECT' 'PROJECT '.
where "PROJECT. "" PROJ_ID "=" RESOURCES_ON_PROJECTS. " "" PROJ_ID.
and 'PROJECT '. "" "PROJ_ID '=' COST. PROJ_ID.
PROJECT group. PROJ_NAME, PROJECT. PROJ_DESCRIPTION, RESOURCES_ON_PROJECTS. ACCOUNTABLE_RESOURCE_ID

the result is:

Advisory services CDM 1 10500
Advisory services CDM 2 10500
ESCO effective effective lighting 3 14850
ESCO effective effective lighting 4 14850

It gives a new line for each different resource.


I want to:
Advisory services CDM 10500 1/2
ESCO effective effective lighting 14850 3/4

any help will be appreciated.

Published by: Rahul Gupta on September 7, 2009 16:07

Rahul Gupta says:
Shadow of Blu,

It's exactly what I wanted. But the measures specified by you are not clear for me.

can you let me know how I can implement?

Okay... Let's take the internal selection...

SQL> select proj_name
  2        ,proj_desc
  3        ,resource_id
  4        ,cost
  5        ,row_number() over (partition by proj_name order by resource_id) as rn
  6  from output
  7  /

PROJ_NAME PROJ_DESC               RESOURCE_ID       COST         RN
--------- ----------------------- ----------- ---------- ----------
CDM       Advisory Services                 1      10500          1
CDM       Advisory Services                 2      10500          2
Efficient ESCO Efficient lighting           3      14850          1
Efficient ESCO Efficient lighting           4      14850          2

SQL>

This affects a line number for each line, each group proj_name (partition). Line numbers are allocated in the order of the id_ressource.

Now, using a (hierarchical) query connection we create a hierarchy of folders as well as RN = 2 is considered to be a child of RN = 1, etc..

SQL> ed
Wrote file afiedt.buf

  1  select level
  2        ,lpad(' ',(level-1)*2,' ')||x.proj_name as proj_name -- indent for hierarchical illustration only
  3        ,x.proj_desc
  4        ,x.resource_id
  5        ,x.cost
  6        ,x.rn
  7  from (
  8        select proj_name
  9              ,proj_desc
 10              ,resource_id
 11              ,cost
 12              ,row_number() over (partition by proj_name order by resource_id) as rn
 13        from output
 14       ) x
 15  connect by proj_name = prior proj_name and rn = prior rn + 1
 16* start with rn = 1
SQL> /

     LEVEL PROJ_NAME       PROJ_DESC               RESOURCE_ID       COST         RN
---------- --------------- ----------------------- ----------- ---------- ----------
         1 CDM             Advisory Services                 1      10500          1
         2   CDM           Advisory Services                 2      10500          2
         1 Efficient       ESCO Efficient lighting           3      14850          1
         2   Efficient     ESCO Efficient lighting           4      14850          2

SQL>

Now, using the sys_connect_by_path function we can get it to collect the data, because it passes through to the bottom of the hierarchy...

SQL> ed
Wrote file afiedt.buf

  1  select level
  2        ,lpad(' ',(level-1)*2,' ')||x.proj_name as proj_name
  3        ,x.proj_desc
  4        ,x.resource_id
  5        ,sys_connect_by_path(resource_id,'/') as resources
  6        ,x.cost
  7        ,x.rn
  8  from (
  9        select proj_name
 10              ,proj_desc
 11              ,resource_id
 12              ,cost
 13              ,row_number() over (partition by proj_name order by resource_id) as rn
 14        from output
 15       ) x
 16  connect by proj_name = prior proj_name and rn = prior rn + 1
 17* start with rn = 1
SQL> /

     LEVEL PROJ_NAME       PROJ_DESC               RESOURCE_ID RESOURCES        COST         RN
---------- --------------- ----------------------- ----------- ---------- ---------- ----------
         1 CDM             Advisory Services                 1 /1              10500          1
         2   CDM           Advisory Services                 2 /1/2            10500          2
         1 Efficient       ESCO Efficient lighting           3 /3              14850          1
         2   Efficient     ESCO Efficient lighting           4 /3/4            14850          2

SQL>

Now, we can store up to the sys_connect_by_path to eliminate the left "/" simply by using the TRIM function.
We also need to do however is to choose only the lines that have reached the bottom of the hierarchy (the nodes). We have a pseudo-device column we can refer to called CONNECT_BY_ISLEAF...

SQL> ed
Wrote file afiedt.buf

  1  select level
  2        ,lpad(' ',(level-1)*2,' ')||x.proj_name as proj_name
  3        ,x.proj_desc
  4        ,x.resource_id
  5        ,ltrim(sys_connect_by_path(resource_id,'/'),'/') as resources
  6        ,x.cost
  7        ,x.rn
  8        ,connect_by_isleaf
  9  from (
 10        select proj_name
 11              ,proj_desc
 12              ,resource_id
 13              ,cost
 14              ,row_number() over (partition by proj_name order by resource_id) as rn
 15        from output
 16       ) x
 17  connect by proj_name = prior proj_name and rn = prior rn + 1
 18* start with rn = 1
SQL> /

     LEVEL PROJ_NAME       PROJ_DESC               RESOURCE_ID RESOURCES        COST         RN CONNECT_BY_ISLEAF
---------- --------------- ----------------------- ----------- ---------- ---------- ---------- -----------------
         1 CDM             Advisory Services                 1 1               10500          1             0
         2   CDM           Advisory Services                 2 1/2             10500          2             1
         1 Efficient       ESCO Efficient lighting           3 3               14850          1             0
         2   Efficient     ESCO Efficient lighting           4 3/4             14850          2             1

SQL>

So now we can filter only the lines where CONNECT_BY_ISLEAF = 1, also remove the output columns and calculates values etc, we don't need to see.

SQL> ed
Wrote file afiedt.buf

  1  select x.proj_name
  2        ,x.proj_desc
  3        ,ltrim(sys_connect_by_path(resource_id,'/'),'/') as resources
  4        ,x.cost
  5  from (
  6        select proj_name
  7              ,proj_desc
  8              ,resource_id
  9              ,cost
 10              ,row_number() over (partition by proj_name order by resource_id) as rn
 11        from output
 12       ) x
 13  where connect_by_isleaf = 1
 14  connect by proj_name = prior proj_name and rn = prior rn + 1
 15* start with rn = 1
SQL> /

PROJ_NAME       PROJ_DESC               RESOURCES        COST
--------------- ----------------------- ---------- ----------
CDM             Advisory Services       1/2             10500
Efficient       ESCO Efficient lighting 3/4             14850

Tags: Database

Similar Questions

  • Combining the NACHA several files into one

    Gurus, we will implement the new file format NACHA for our payroll service. Payroll running a DOS command to concatenate several files into one .mf. Is there a way to Oracle to achieve the same?

    Database server
    ----------------------------------------
    RDBMS: 11.2.0.3.0
    Oracle Applications: 11.5.10.2


    Thanks, Naveen Gagadam.

    Published by: mascot of Oracle on May 30, 2013 10:26

    Vignesh Hi, I just went through our Installer and there are Consolidation defined for each payroll that we use. I think it is better the purpose of having a consolidation set. Could you tell me how to consolidate several salary mass as a whole or alternatively can add several wage masses on the fly (as parameters) for each race NACHA?

    Thanks, Naveen.

  • Concatenate several lines in a Unique identifier

    Hi all

    I need to concatenate several lines in a unique identifier

    So, my unique identifiers are name and email_id columns.


    It is 1:M relationship as eponymous and email_id can have n number of different products, now I should


    So let's say that the name = xyz and [email protected] has 5 rows with different product info for them.

    Product # #Name #email_id

    XYZ [email protected] Ora
    XYZ [email protected] sql
    XYZ [email protected] siebel
    XYZ [email protected] erp
    XYZ [email protected] crm

    My end result would be after concatenation (seen / as a delimiter between each concatenated row):

    Product # #Name #email_id
    XYZ [email protected] Ora/sql / / erp/crm siebel

    Need help please, after several attempts, I can't seem to make it work. I thank in advance

    Published by: user13080645 on January 22, 2011 07:33

    Hello

    You should look at using STRAGG or LISTAGG - take a look on: http://www.dba-oracle.com/t_display_multiple_column_values_same_rows.htm or search the Forum of SQL for these

    Andy

  • Y at - it a safe application for concatenating several files into one .rtf?

    Y at - it a safe application for concatenating several files into one .rtf?

    Why do you do this?

    Is it arril (3D image files) or .rtf (Rich Text Format) files?

  • How to scan several documents into one PDF

    How to scan several documents into single PDF - have no ADF

    Thanks - great app

  • How to display/concatenate several lines into one line

    I have a report that retrieves a project name and its corresponding attached resources.
    If tha project has 4 resources attached will appear 4 different columns.
    is there a way to display a single line with the corresponding resources names concatenated into a single cell?

    There is a related issue of PL/SQL and is not a matter of apex. However, see this as an example:

    http://Apex.Oracle.com/pls/OTN/f?p=31517:84

    There are also a bunch of other code related to this issue.

    Denes Kubicek
    ------------------------------------------------------------------------------
    http://deneskubicek.blogspot.com/
    http://www.Opal-consulting.de/training
    http://Apex.Oracle.com/pls/OTN/f?p=31517:1
    ------------------------------------------------------------------------------

  • Morphing several objects into one.

    I can't morphing 4 photos in one. No idea how because I do not know where to start as I am a newbie to the animation graphics and eager to learn.

    I set up entirely in illustrator and use this technique I wrote a tutorial for a bunch of years:

    http://library.CreativeCOW.NET/articles/gerard_rick/morph.php

    Simply configure you your different shapes in Illustrator, using the blending mode to create up to 256 intermediate forms between the two, develop, release them in layers and then import them into a comp in AE and sequencing layers.

  • OfficeJet J6480 scan several Documents into one file

    Hello

    I have an Officejet J6480 on a Mac. I want to scan several documents and saved it as a PDF file. I don't know how to do this.

    Put the original in the high plateau of the loader page in the printer.  Open Device Manager from the Dock on your Mac HP and double click on Scan to PDF (or could say scan Document).

  • HP 3511 scan several documents into one file

    How to scan several documents in the same file to my HP3511?  I am running Windows 7.

    This printer does not have an automatic feeding for print/copy/scan.  Is it possible to do without it?

    Thank you.  I always do the printer instead of the computer, so that it is useful!  Unfortunately, it works to scan; However, it would still not save them all as a single file.  I went back and checked the advanced settings, and is not checked to create a separate file.  He has created a file for all 5 pages.  He was using the file name I gave him and then added extensions 0001, 0002, 0003, 0004 and 0005.

    Ugh.  I'll try again.

  • The rendering of several clips into one video file?

    Hello

    I'm completely new Premiere Pro. I decided to make my first video.

    Here's what I did. I added my clip to the timeline, then I used the razor tool twice in order to slice clip in 3 small clips. Then I applied basic effects to a small clip in the middle.

    So I decided to make the entire images. I put 'In' at the beginning of the first clip and placed 'Out' at the end of the last clip.

    After I clicked on "make Sequence - in at Out ' I see that Premiere Pro product 4 videos: three videos of each of those that contains appropriate slice of the original clip and the 4th video seems to contain only 1 image of the original clip:

    Premiere Pro Rendering Video 1.png

    Here are all the files created during the rendering process:

    Premiere Pro Rendering Video 2.png

    So, instead of making 4 videos I need first to render the images together in a single clip. Please could you tell me how I can do?

    I also tried to select all 3 clips and then made selection, but unfortunately I got the same result as above.

    Thank you!

    Thank you guys!

    Yes, later that day I already understood how do. Nowdays Youtube is a source of all knowledge. I just look for "how this ' and ' how '. Previously, I used Sony Movie Studio 12, but after reinstalling OS on my PC, I decided to try Premiere Pro.

    BTW, here is my first video. I spent probably 5 to 6 hours yesterday learning first LOL just to make this clip!

    Christmas in October! -YouTube

  • How can I connect three different files into one? Thank you.

    I need to download copies, but I need to combine into one file

    Hello

    Here is the link for the steps on how to merge several PDF' into one.

    Acrobat help. Combine files

    As shown above, you would need Acrobat for that.

    Concerning

    Sukrit diallo

  • Representing data of several lines into one line

    Hi all

    Please check the query below:
    select manager_id mg_id, employee_id emp_id, last_name name from employees 
    where manager_id = '100'
    and DEPARTMENT_ID = '80'
    If I run the following query, o/p then comes wise line; as below:
           mg_id           emp_id            name
           100             145                     Russell
           100             146                     Partners
           100             147                     Errazuriz
           100             148                     Cambrault
           100             149                     Zlotkey
    But if I want the o/p as below; That is to say; under Manager # 100, all employees emp_id and name should come in ONE row NOT in several lines:
    mg_id                   emp_id     name          emp_id       name       emp_id     name         emp_id     name                emp_id         name
    100                             145             Russell     146       Partners        147     Errazuriz       148              Cambrault        149        Zlotkey
    pls help me sort the above desired o/p.

    kindly tell me if there are guidelines of accounting (except 'Plain Text help' on the right side) in this forum. I tried a lot of post above 2 o/p in easy to read format, but could not do so.

    Published by: Francis Sep 20, 2009 04:28

    Published by: Francis Sep 20, 2009 04:29
  • grouping of several lines into one line

    Totally, I need help with this easy... Basically, I have several lines for a unique userid that I need to be grouped into a single line.

    Here's what I have before:

    USER ID MONTH1_SEVERITY MONTH2_SEVERITY MONTH3_SEVERITY

    MODERATE 1900055
    1900055 <... it'sa just space... > MODERATE
    1900055 <... it'sa just space... > MODERATE


    What I wish to see:
    USER_ID MONTH1_SEVERITY MONTH2_SEVERITY MONTH3_SEVERITY

    MODERATE MODERATE MODERATE 1900055


    Thanks in advance.

    Rotate the data

    Select user_id,
    Max (month_1_severity),
    Max (month_2_severity),
    Max (month_3_severity)
    from table_name
    Group of user_id

  • In Windows 7 we select several lines of data that are in a different location on the page (no continuous lines) through the mouse or keyboard and also can we copy all lines of these different at the same time to paste somewhere else in one fell swoop.

    > Now I'm unlable to select more number of lines that are not a sequence in a single page to copy the data rows and paste somewhere in one fell swoop.
    > Is this concept implemented in Windows 7. ?
    > Is there a provision (method) to select several lines that are not continuous across the keyboard or the mouse in windows 7?

    Byagaris,
    It depends on what program you are trying to copy and paste into.  You are able to select continuous, multiple lines, by using the Ctrl Key and clicking, or by highlighting the desired line.  For example, I held the Ctrl key and then, using the mouse, has highlighted several different phrases in the various paragraphs, and could then copy them.  This feature is available for several versions of windows.
    If you are not able to perform this action then post what happens when you try and what program you try it.
    Mike - Engineer Support Microsoft Answers
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • deleting several lines in a report?

    db11gxe, apex 4.0, firefox 24,

    How to delete several lines in a report at the same time?

    Thank you

    Hi newbi_egy,

    Here's a demo with a few steps that can be used in your scenario-

    (1) this is the query for a report on the emp table that has column empno with values single-

    SELECT APEX_ITEM.CHECKBOX(1,empno) " ", ename, job FROM   emp ORDER  by 1
    

    (2) a button Delete is created that submits the page.

    (3) a sur-soumettre the process is created with point process on submit - after calculations and Validations to determine that the sub process is running when you click the button remove.

    BEGIN
    FOR i in 1..APEX_APPLICATION.G_F01.count
    LOOP
    delete from emp where empno=APEX_APPLICATION.G_F01(i);
    END LOOP;
    END;
    

    I hope this could help you.

    Kind regards

    Das123

Maybe you are looking for

  • Re: Windows XP Setup does not work on Satellite A300-1EG

    I am trying to install WinXP on this laptop. The CD starts correctly, the message on the system configuration, but then screen turns white and HARD drive led lights. When I start pressing the keys, it starts to beep after I pressed several keys. I di

  • Application of Lenovo

    I reinstalled win8.1 using a different CD on my ThinkPad 11th Yoga, and I was wondering where can I download the software? (I'mloking for NSOs are in the image)

  • Cannot install service Pack2 dllcache copy

    Recently reformatted my computer with a new copy of windows XP home. After update service pack 2 during its installation, I get hundreds of reviews saying "cannot copy the abcdefg.dll file to ensure that the location below is correct, or change it an

  • I currently have 91 processes running and 20 of them are svchost.exe

    I have a toshiba satellite A135-S4467 with an Intel (r) Core (TM) 2 CPU TS5200 @ 1.60 GHz.  I am running Windows Vista Home Premium.  An operating system for 32-bit with 2 GB of RAM.  My computer is not working as it should... for example I get "not

  • Upgade JOINT-2 6.0 (3) E1 to 6.1 (1) E1

    Question, should I move to 4,0000 E1 or 1.0000 E1. If I go directly to 1.0000 E1 do we need to load 4,0000 before E1? Thank you