How to select the group header with detailed data in a SQL
Dear SirI wish I had a little help from you. My goal is to create a view where the data should be in the appropriate format. In this format, I want to have for each header of a group.
I have 3 tables that they ar connected to the other (representing hierarchical data where financial plan breaks in different groups).
CRM_PLAN
CRM_PLAN_ID
DATE
AMOUNT
CRM_PLAN_PE
CRM_PLAN_PE_ID
TITLE
AMOUNT
CRM_PLAN_ID (REF CRM_PLAN key. CRM_PLAN_ID)
CRM_PLAN_MONTH
CRM_PLAN_MONTH_ID
YEAR
MONTH
AMOUNT
CRM_PLAN_PE_ID (foreign key to CRM_PLAN_PE. CRM_PLAN_PE_ID)
Data looks like:
CRM_PLAN
CRM_PLAN_ID | DATE | AMOUNT
1. 01.01.2012. 500
2. 01.02.2012 | 200
CRM_PLAN_PE
CRM_PLAN_PE_ID | TITLE | AMOUNT | CRM_PLAN_ID
1. Organization 1. 100. 1
2. Organization 2. 400. 1
5: 3 organization | 200 | 2
CRM_PLAN_MONTH
CRM_PLAN_MONTH_ID | YEAR | MONTH | AMOUNT | CRM_PLAN_PE_ID
1. 2012 | 1. 60. 1
2. 2012 | 2. 40. 1
5: 2012 | 1. 350. 2
4. 2012 | 2. 50. 2
3: 2012 | 1. 200 | 3
I would like to than the view that returns data as:
MONTH | AMOUNT
Organization 1. null
1. 60
2. 40
Organization 2. null
1. 350
2. 50
3 organization | null
1. 200
The main question is hot to write a sql as source for display to insert before each group a line with the value of the title of the table CRM_PLAN_PE column. Is it still possible? Perhaps you could suggest another method.
Notice will be used in the form of oracle where will be possible to change the data - I will make the necessary arrangements by trigger INSTEAD of.
Kind regards
Igor
Published by: user5528050 on 29.11.2012 02:23
Published by: user5528050 on 29.11.2012 02:24
Published by: user5528050 on 29.11.2012 02:25
Hi, Igor,.
In this case, I think ROLLUP is a little simpeler GROUPING SETS, but you could do it anyway:
SELECT CASE
WHEN GROUPING (tab2.id) = 0
THEN TO_CHAR (tab2.id)
ELSE tab1.title
END AS col_1
, SUM (tab2.amount) AS col_2
FROM tab1
JOIN tab2 ON tab1.id = tab2.tab1_id
GROUP BY tab1.title
, ROLLUP (tab2.id)
ORDER BY tab1.title
, GROUPING (tab2.id) DESC
, tab2.id
;
If tab2.id cannot be NULL, you can use
NVL ( TO_CHAR (tab2.id)
, tab1.title
)
instead of the CASE expression and simplify the ORDER BY clause to
ORDER BY tab1.title
, tab2.id NULLS FIRST
Tags: Database
Similar Questions
-
How to separate the invoice header and details by a blank page in between
Hello
I need to print an invoice report where there should be a blank between the header and the details.
I have company to print the invoice on both sides of a page so that the details starts on 3 empty page on page 2.
In other words, how to insert a page break in the RTF template, such that there will be a blank page between invoice and detail at the exit heading.
Help, please
Thank you
Yogi
Published by: Yogi on January 25, 2013 15:55Try the example that I gave you
-
SQLLDR: How to fill the empty columns with specific data by default?
Hello
We are 11G
Here is a complete example:
(1) the definition of the table:
(2) the CTL:create table IMPORT_PRJ_TIMESHEETS ( RESSOURCE_CODE VARCHAR2(20), REFERENCE_DATE VARCHAR2(20), STATUS VARCHAR2(20), PROJET_CODE VARCHAR2(50), TACHE_ID VARCHAR2(100), TACHE_DESC VARCHAR2(250), RAF NUMBER, JOUR1 NUMBER, JOUR2 NUMBER, JOUR3 NUMBER, JOUR4 NUMBER, JOUR5 NUMBER, JOUR6 NUMBER, JOUR7 NUMBER, IMPORT_DATE DATE );
LOAD DATA CHARACTERSET WE8ISO8859P1 APPEND INTO TABLE IMPORT_PRJ_TIMESHEETS -- Pour eliminer la ligne d'en-tete WHEN PROJET_CODE != 'ID projet' FIELDS TERMINATED BY '*-*' OPTIONALLY ENCLOSED BY '"' ( RESSOURCE_CODE CONSTANT '!RESSOURCE_CODE!' , REFERENCE_DATE CONSTANT '!REFERENCE_DATE!' , STATUS CONSTANT '!STATUS!' , PROJET_CODE CHAR , TACHE_ID CHAR , TACHE_DESC CHAR , RAF CHAR "TO_NUMBER( :RAF, '999G999D99')" , JOUR1 CHAR , JOUR2 CHAR , JOUR3 CHAR , JOUR4 CHAR , JOUR5 CHAR , JOUR6 CHAR , JOUR7 CHAR , IMPORT_DATE SYSDATE ) {code} 3) the datafile : {code} ID projet*-*ID tâche*-*Tâche/Description*-*RàF*-*lun. 13/07*-*mar. 14/07*-*mer. 15/07*-*jeu. 16/07*-*ven. 17/07*-*sam. 18/07*-*dim. 19/07*-* FR-FR-NT2300135*-* *-*GAMMAWEB - Coordination*-*0,00*-* *-* *-* *-*8,00*-*8,00*-* *-* *-* *-* *-*Holiday*-* *-* *-*8,00*-* *-* *-* *-* *-* *-* *-* *-*Special leave*-* *-*8,00*-* *-* *-* *-* *-* *-* *-* *-* *-*Vacation*-* *-* *-* *-*8,00*-* *-* *-* *-* *-* {code} - As you can see, the datafile delimiter is "*-*" .... there's no pb about this. - Also, there are 5 lines in the datafile. Currently, the _*load status*_ is : - Line 1 is the header >>> not loaded, and that's fine with me. - Line 2 is successfully loaded - Line 3 / Line 4 / Line 5 : are not loaded .. but I need these lines ... *What I'd like to get is to successfully load lines 3 to 5 with a default values for the first 3 columns (project/task ID/ task desc)* I hope it's clear enough and that you will be able to provide a good answer .. Thanks in advance, Olivier
In your example, the only ranked with value on all lines is TACHE_DESC.
If this field is always filled, try this:
WHEN TACHE_DESC! = "Task/Description".Concerning
-
How to delete the 2 files with expiration date 25/07/2014?
Found 2 records in history settings - display the files. type-txt doc. cannot delete I suppose that's the expiration date. How can I change the date? or y at - it another way to remove? Also have a damaged object - visualization of objects that I cannot remove.
Click on Security tab, uncheck keep favorite Web sites. then delete the history.
Still have a problem with the damaged object - type active x control id but nothing else has.
-
How to hide the table header if no data is present
Hello
I need to hide the heading for the table if no data is present. Table a, column 5. If no matter what clolumn gave this section table should not be display.
I use <? If: count (Installation_Event_S19) = 0? > but this is not a job for me.
Could you please help me.
Thank you
Sylvie Kumar
I think you want to show/hide a table that if its conditions of licence exists and have some value. You can have an if condition including the table.
-
How to remove and hide the group header
Hello
I want to combine metadata fields and you want to give the name to the group. But I want to remove the skin on the page.
Please provide inputs on how to achieve this.
Thanks in advance
You can set disableFieldGroupHeaders = 1 to completely hide the group header.
To just remove the link to hide, you can set the following in a side effect of rule:
<>
'$>
<$exec setresourceinclude("std_field_group_header_show_hide",="" std_field_group_header_show_hide)$="">
Jonathan
$exec> -
How to select a group nested in the PS?
When I use the self-select: Group option, it will select only the group most in which is placed my layer clicked; but I use a lot of groups nested inside other groups. Is there a way to change higher or lower level groups?
Select the Group of lower level by clicking in the layers panel is tedious, because when I click on a layer with the value automatic selection 'Sex', it will automatically expand groups in which it is placed and I have to scroll up to find the layer group.
Are you aware of the pop - up we get when ctrl-click with the tool move?
-
How to select entire groups or to multiple recipients in MAIL, rather than one at a time?
One way is to use the app to create a group with the intended recipients. Then when composing the email just type the group name in the To: field.
-
How to select the pieces of my image in black and white?
How to select the pieces of my image in black and white? FOW example letter J or the circle or the two together?
It's actually pretty easy, but I have to assume that you know a few basics in Photoshop
(1) open your existing image
(2) double click on the layer and the 'layer style' appears. In the mix if area set the sliders so the whites in the image disappears
You will be left with just the black elements in design
(3) duplicate layers
and merge them together
to give a standard layer
(4) ctrl or cmd click on the layer to select and create a layer mask
(5) you now have a mask of the image. Duplicate the layer, click alt or option, click on the layer mask to call
(6) the blacks and the whites are not completely black and white for the use of levels to adapt to the absolutes
(7) now you have to decide what you want to select. In this case, I chose the lettering and simply covered everything else to the top with black. You do this by lasso selection and fill and items when it's delicate brush just the details with a black brush "hard." .
(8) at this stage, you can do what you want you have a layer mask. So you can color the text for example
or place in a background color and apply a layer as Beveling effect
Hope that makes some sense. It is much easier to do than to describe.
-
How to use the Group feature in insert or update
Hai All
How to use the Group feature in insert or update statement
I'm generating attendance so I have a different set of timing example
0800,1200,1230, 1700 and I need to insert data into the table that contains the intimate value min and max value for
outtime and othere to inertval time in or out
Pls tell me with some examples
For example
For INSERT
Insert into T2 (barcode, empcode, respondent, attend_date)
values (R2.cardn, R2.enpno, min(R2.) PtIMe), R2.pdate);
Update
Update dail_att set outtime = MAX (r2.ptime) where empcode = r2.enpno and barcode = r2.cardn and
attend_date = r2.pdate;
Here, in the place where I used to have so pls tell how to use
Thanks and greetings
Srikkanth.MHi Srikkanth.M
to insert:
insert into test (dummy) values ((select max (dummy) to double));
Update:
Update test dummy value = (select max (dummy) to double where to test them. XXXXField = double. XXXXField);
-
Printer all in one HP3520 - how to select the wireless network and enter the WEP key?
According to print my wireless network is detected.
How to connect the! @# % printer $ fo the wireless network and enter the WEP key?
Instructions on the HP site tell me to selet NETWORK on the printer control panel. Well, there's a way to select the NETWORK from the control panel. It is not an option for him.
I downnloaded and installed the latest drivers.
I have restored the default settings.
How to select the wireless network and enter the WEP key?
All of HP's instructions seem to be for a newer printer with a touchscreen.
I want that the printer is connected to my main computer via the USB port. I want to be able to print wireless phones and tablets.
My 3520 is not a 'touch Screen' and it has wifi.
However, the following work:
Try to open the HP Deskjet 3520 icon, open the utilities tab, click on convert USB wireless, by following the steps on the screen.
This leads me to believe that ONLY the wireless doesn't work. I know now that the part of the sentence "Convert USB to wireless connection" is supposed to mean "works like USB and wireless.
Thank you for your help
-
How to use the ESD document with structured templates
Hello
I started to learn working with SEDD. I have an existing ESD, now I'm suppose to use it to create documents. I created a new book and imported this ESD file to it. I can see all the items in the catalog of the element. But when I start to add items to the book and add a new document, the elements are turning to red. Referring to the User Guide, it is said EDD cannot be used directly and must be used with structured patterns. But I do not have these models structured with me. Can someone please tell me how to create these structured templates and how to use the ESD file with these models, and out of this problem.
Thanks in advance.
Although ESD exist in the form of a separate document, the only way that it can be used is when it is part of the model. As a model of structured FrameMaker, a structured model contains master pages, pages reference, character formats, paragraph formats, etc. IN ADDITION, a structured model contains a DSP. To add the EDD to your template file, or any document FrameMaker who will use it, open the template file and the file of ESD. Click anywhere in the template file, and then select file > import > element definitions. In the dialog box, select the EDD file as source and click Import. Then save the template file.
To use the template file, open it and save it as a FrameMaker document, giving it the name you want. You can now create your structure.
If you use a book, all documents in the book must use the same ESD. Open the template file. In the book file, select all the documents in the book. Then select file > import > element definitions. In the dialog box, select the template file and click Import. Once completed, all documents in the book have the same ESD. In addition, ESD is copied into the file of the book itself.
You say:
But when I start to add items to the book and add a new document, the elements are turning to red.
It is is not clear to me what you do. While it is true that SOME elements of a book are in the book file, you cannot add a book of items in the folder (at least not as far as I know). In general, the book file, it encapsulates elements around the documents root elements in the book. You may need to update the book to get a part of the Red disappear lines. You may need to rearrange items in the structure of the book to remove the red lines.
Hope this helps,
Van
-
How to create the new domain with lookup?
How to create the new domain with list of choices like terrain dDocType system?Administration/Admin Applets tab / SCCM / information fields.
Add field or edit a custom field if you have one.
The name field (the name will be prefaced with the lowercase letter x behind the scenes, if ever, you write the code to call it if you name this Fruit it will xFruit for code)
Define your values for the field, but the important thing for a menu drop-down list or list of selection will be to list the Option activate the checkbox.
Then, you perform one of the 3 main things to put data in the list.
1. manually fill in a list of options
2. use a DB or DB table view to view Configuration Manager
3. create a complex tree (read the documentation on which I him have not used)If this does not answer your questions, click the help button in the applet.
-
LOBs and how to retrieve the record inserted with EMPTY_BLOb()
Hi guys
How to retrieve the records inserted with EMPTY_BLOb() instead of NULL value.
Best greetings
A.G.There must be a better way, but these work:
SELECT... from tableX where length (lob_column) = 0;
SELECT... from tableX where dbms_lob.getlength (lob_column) = 0;Concerning
Jonathan Lewis
http://jonathanlewis.WordPress.com
http://www.jlcomp.demon.co.UK"All experts it is a equal and opposite expert."
Clarke -
How to play the next song with the repetition of the same song over and over again
How to play the next song with the repetition of the same song over and over again.
In this screenshot, shot an Apple article, you can see four icons at the bottom of the screen. Look at the third argument of the right, with the two arrows going in a circle. It's the repeat function. When turned on, you can tap the icon to turn it off.
Maybe you are looking for
-
Satellite L300 14 c: drivers XP for display & high speed Modem
Hello! I have loaded Windows XP - SP2 on Satellite L300 14 C model PSLB0E-02T01XGR. Almost all drivers are in & work fine except the following: 1. impossible to locate the display driver. Display resolution limited to 1024 x 768. Try to load the driv
-
I can't sign into windows live messenger, I get the message that windows live messnger is unavailable currently try again later and also I get the error code 80048820, can someone help me solve this problem.
-
Error installing Windows 7 on Precision T5400 with Configuration RAID 1
Hello I need yout help to understand why I'm not able to install Windows 7 on my Precision t5400 workstation. I get this error at the end of installation "installation of windows could not configure windows to run on a hardware on this computer." I h
-
Aproval question...
I sent my application signed for PlayBook a few days ago.
-
mail error ID: OX80070005
Excuse my English, I tried to send some pictures to a relative, and the last two days, Windows live mail does not work. I get error massage ID: OX80070005. I tried set-aside education aid in the mail and no luck. Please help Roberto