PL/SLQ - How to create query with horizontal running totals
Hi:
I'm trying to create a report in the following format
Year Name Reg1 Reg2 Reg3
2001 Al 3 4 5
2001 Le 4 1 1
2001 7 5 6
2002 Sue 2 4 1
2002 Al 1 3 6
2002 Jim 6 1 3
2002 16 15 16
2003 Jim 4 -3 2
2003 Le -2 4 5
2003 20 16 23
Note that the totals are accumulating horizontally, broken on year. How do I do that, please? Thanks very much!
Al
Hi, Al,
Welcome to the forum!
978108 wrote:
Hi:
I'm trying to create a report in the following format
Year Name Reg1 Reg2 Reg3
2001 Al 3 4 5
2001 Le 4 1 1
2001 7 5 6
2002 Sue 2 4 1
2002 Al 1 3 6
2002 Jim 6 1 3
2002 16 15 16
2003 Jim 4 -3 2
2003 Le -2 4 5
2003 20 16 23 You may have noticed that this site normally doesn't display multiple spaces in a row.
Whenever you post formatted text (such as query results) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
If you do that, your desired output will be much more readable:Year Name Reg1 Reg2 Reg3
2001 Al 3 4 5
2001 Le 4 1 1
2001 7 5 6
2002 Sue 2 4 1
2002 Al 1 3 6
2002 Jim 6 1 3
2002 16 15 16
2003 Jim 4 -3 2
2003 Le -2 4 5
2003 20 16 23
Note that the totals are accumulating horizontally, broken on year. How do I do that, please? Thanks very much!
AlHere's one way to do that:WITH yearly_summary AS
SELECT year
, SUM (SUM (reg1)) OVER (ORDER BY year) AS reg1
, SUM (SUM (reg2)) OVER (ORDER BY year) AS reg2
, SUM (SUM (reg3)) OVER (ORDER BY year) AS reg3
FROM table_x
GROUP BY year
SELECT year, name, reg1, reg2, reg3
FROM table_x
UNION
SELECT year, NULL, reg1, reg2, reg3
FROM yearly_summary
ORDER BY year, name
Edited by: Frank Kulash on Dec 20, 2012 3:04 PM
Corrected query.
Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data. For example:CREATE TABLE table_x
( year NUMBER
, name VARCHAR2 (10)
, reg1 NUMBER
, reg2 NUMBER
, reg3 NUMBER
INSERT INTO table_x (year, name, reg1, reg2, reg3) VALUES (2001, 'Al', 3, 4, 5);
INSERT INTO table_x (year, name, reg1, reg2, reg3) VALUES (2001, 'Le', 4, 1, 1);
INSERT INTO table_x (year, name, reg1, reg2, reg3) VALUES (2002, 'Sue', 2, 4, 1);
INSERT INTO table_x (year, name, reg1, reg2, reg3) VALUES (2002, 'Al', 1, 3, 6);
INSERT INTO table_x (year, name, reg1, reg2, reg3) VALUES (2002, 'Jim', 6, 1, 3);
INSERT INTO table_x (year, name, reg1, reg2, reg3) VALUES (2003, 'Jim', 4,-3, 2);
INSERT INTO table_x (year, name, reg1, reg2, reg3) VALUES (2003, 'Le', -2, 4, 5);
Also, say which version of Oracle you're using. In this case, it may not matter. The query above will work in Oracle 9.1 and higher.
Similar Messages
-
How to create a loop to run total of records for before and after unconstant date
Post Author: Ann2
CA Forum: Formula
Here is the data sample:
ID period code date
1 00 I 01/01/1999
1 00 Z 01/02/1999
1 00 G 12/05/1999
1 00 M 01/01/2000
There are many students with many periods and many codes. I need to save a date when code = 'G' and count separateley records per student/period 2 times - before and equal that date and after that date, so in the end for period 00 I will have 2 values: 3 (before) and 1(after).
There are periods from 00 to 08. I am counting students abscencies before and after warning letter was sent (code G).
The result data should look : 00 01 02 03 04 05 06 07 08 00 01 02 03 04 05 06 07 08 Total
3 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 4
Please help me.
Thank you.
Ann2Post Author: Ann2
CA Forum: Formula
Thank you for your answer, but I do care about the date the 'G' happened, because I need to reset count.
The logic behind is this:if a student absent for more than 8 times per period - the letter will be sent out to the parents , that will be code 'G' with period '-1' (it may happen that there will never be code 'G' , but I need to track all absencies). Once the letter is sent, the count starts over (the count starts over the next day after code 'G'). The absencies which happened before or the date the letter sent should count toward 'previous' abscenices, all other - absenices after the letter.
So basically I need total per period and total per period before or the day with code 'G'. Running total with reset with formula code = 'G' does not work.
I created a formula field which has global date (when code 'G' happenned) and it says if globaldate >= periodDate then date (1900,01,01) else (2100,01,01) and that formula is ok, but I can not use it in running total or can not create group on it and insert total.
Please help me with this. Thank you.
Ann2 -
LOV Select List How to create query with begin & End in LOV
Dear All,
i am using Apex 3.2 ver
i want to use below code in LOV select list
BEGIN
IF UPPER(:P23_SERVICE_TYPE) like 'GUIDE%' THEN
SELECT NAME D, CODE R FROM SPECIAL_SERV_MAS
WHERE NVL(ACTIVE_FLG,'N') = 'Y'
AND NVL(GUIDE_FLAG,'N') = 'Y'
and CITY_CODE LIKE NVL (:P23_CITY_CODE, '%')
ORDER BY 2
ELSIF
UPPER(:P23_SERVICE_TYPE) LIKE 'ACCOM%' THEN
SELECT NAME D, CODE R
FROM HOTEL_MAS
WHERE NVL (ACTIVE_FLG, 'N') = 'Y'
AND CITY_CODE LIKE NVL(:P23_CITY_CODE,'%')
ORDER BY PRIORITY
END IF;
END;When i put this code in my LOV Select list Section then display me Error
Not Found
The requested URL /pls/apex/f was not found on this server.
Oracle-Application-Server-10g/10.1.2.0.2 Oracle-HTTP-Server Server at tidevserv1 Port 7777
How to Resolve it.Hi Vedant,
you dont need to use begin ...end block
Try the Below code
IF UPPER(:P23_SERVICE_TYPE) like 'GUIDE%' THEN
RETURN
'SELECT NAME D, CODE R FROM SPECIAL_SERV_MAS
WHERE NVL(ACTIVE_FLG,''N'') = ''Y''
AND NVL(GUIDE_FLAG,''N'') = ''Y''
and CITY_CODE LIKE NVL (:P23_CITY_CODE, ''%'')
ORDER BY 2' ;
ELSIF UPPER(:P23_SERVICE_TYPE) LIKE 'ACCOM%' THEN
RETURN
'SELECT NAME D, CODE R
FROM HOTEL_MAS
WHERE NVL (ACTIVE_FLG, ''N'') = ''Y''
AND CITY_CODE LIKE NVL(:P23_CITY_CODE,''%'')
ORDER BY PRIORITY' ;
END IF;In this way you can create conditional LOVs ,
Hope this will helps you.
Regards,
Jitendra -
How to create parameter with multiple selection in a query (SQ02) ?
Hi Exports
Do you know how to create parameter with multiple selection in a query (transaction SQ02)?
thanks.Hi
i know how to create user parameter at SQ02,
the question is how to create multiple selection parameter? -
How to create database with ASM
HI
How to create database with ASM?
I install vmware workstation on window XP .On virtual machine install Linux 5 enterprise (Oracle) install.
I install oracle DB software only. Also make 3 disk for ASM .
1 -- When I want to install oracle DB with ASM . In this process candidate disks not show . Why?
How I can see disks ..
so I simple install oracle DB software only.
2 -- Now I want to create database with ASM by DBCA .
What process I will follow ?
Please guide me
ThanksHi
Steps to create database with ASM.
1.Install oracle binary with active CRS(For single node installation CRS is activated when you run root.sh) .
2.Create disk without file ssytem.
3.Assign disk to raw .
4.Change owner and permission to raw devices.
5.Configure ASM manually or USing DBCA.
Manually ASM Configuration.
a.Create initialization parameter file and password file.
b.Mandatory parameter is "instance_type=asm" as per your need configure rest of parameter like db_cache_size,large_pool_size,processes,remote_login_passwordfile,shared_pool_size etc..
c.To discover disk configure "asm_diskstring=/dev/raw/raw*"
Using DBCA to configure ASM.
1.In storage type section choose ASM.It will ask for password of sysdba in 10g.
2.ASM configuration window will open -> here it create disk group -> it shows all available ASM candidate disk automatical -> choose normal redundancy,external redundancy or high redundancy.
ASM disk also can be conbfigured with ASMLIB .
If ASM disk is configured you can start asm instance in nomount state and query to v$asm_disk to see all candidate disk.V$asm_disk only shows disk which is configured in asm_diskstrings.
Hope this will help U,
Tinku -
How to create complaints with reference to ECC Billing document (CRM 7.0)
Hi experts!
I use ECC 6.0 and CRM 7.0.
I have to create CRM complaints (ZCLR - CLRP) with reference to ecc billing documents.
I read the following topics and help:
1. How to create complaints with referenceto ECC Billing document
2. Re: How can we transfer billing documents from SAP ERP to CRM 2007?
3. http://help.sap.com/saphelp_crm70/helpdata/en/46/029ba32e675c1ae10000000a1553f6/frameset.htm
Made these settings:
1. Define the Business object type
Goto SPRO>CRM>Transaction>Settings for Complaints>Integration>Trnsaction Referencing>Define Object types for Transaction reference
2. Assign Business Object Types to Transaction Types
Goto SPRO>CRM>Transaction>Settings for Complaints>Integration>Trnsaction Referencing>Assign Business Object Types to Transaction Types
3. Implement a BADI - CRM_COPY_BADI_EXTERN.Check Implementation CRM_COPY_BADI_BILLDO for more information on the coding for referencing the ECC Billing document.
Goto SPRO>CRM>Transaction>Settings for Complaints>Integration>Trnsaction Referencing>BAdI: Create Complaint with Reference to External Transaction.
but still do not know,
1) if I should pre-replicate billing documents into CRM ?
2) Or, the system uses the RFC to find these documents in ECC to create reference?
Please help me.
Best regards Kostya.
Edited by: Kostya Khveshchenik on Oct 20, 2010 2:09 PMnot resolved =(
Edited by: Kostya Khveshchenik on Nov 19, 2010 8:50 AM -
How to create Rules with Flex Field mapping in the bpm worklist
I Have created a flex field label and was able to map to the flex field attributes .
But when i try to create a rules , I don't see the label or the flex attributes in the task payload .
Can someone please help is understanding how to create Rules with Flex Field mapping in the bpm worklist .
Even I am also searching for any scripts which will take the flex fields prompts and can directly create a label in the bpm worklist .
Any pointers or suggestion is highly appreciated .Hi,
SE38 -> Enter program
Select Variants button and display. In the next screen, enter a variant name, (If not existing , press Create to create new one), else click on Change.
Now the selection screen will display with a button "Variant Attributes" at the top.
Click on that button.
In the next screen, go to the selection variable column of the date field. Press F4 or drop down and select 'D' for date maintenance.
In the column "Name of Variable (Input Only Using F4)" press F4 or drop down, select whichever kind of date calculation you want and save the variant.
Now whenever you run the prgrm with this variant, date will be displayed by default.
Regards,
Subramanian -
How to create Matrix with Group report layout in xml
Hi,
i would be glad if anyone could tell me How to create Matrix with Group report layout in xml?
Here i am attaching the required design doc
below is the code
select COST_CMPNTCLS_CODE,
-- crd.RESOURCES,
NOMINAL_COST,
cmm.COST_MTHD_CODE,
-- crd.COST_TYPE_ID,
gps.period_code
-- ORGANIZATION_ID
from CM_RSRC_DTL crd,
gmf_period_statuses gps,
CM_MTHD_MST cmm,
CR_RSRC_MST crm,
CM_CMPT_MST ccm
where gps.period_id = crd.PERIOD_ID
and crd.cost_type_id = cmm.cost_type_id
and crd.RESOURCES = crm.RESOURCES
and crm.COST_CMPNTCLS_ID = ccm.COST_CMPNTCLS_ID
and gps.period_code in (:p_period1, :p_period2, :p_period3)
group by COST_CMPNTCLS_CODE, cmm.COST_MTHD_CODE, gps.period_code,NOMINAL_COST
order by 1,2,3,4.
The o/p of the report shoud be as given below
Period-1 Period-2 Period-3 Period-4
COMPONENT
LABOUR - DIRECT
Actual 1 2 3 4
Actual Rate 10 10 10 10
Standard Rate
Var%
DEPRICIATION-DIRECT
Actual
Actual Rate
Standard Rate
Var%
OVERHEAD - DIRECT
Actual
Actual Rate
Standard Rate
Var%
LABOUR - IN DIRECT
Actual
Actual Rate
Standard Rate
Var%
Thanks in advanceYour friend is obviously not a reliable source of HTML
information.
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"Mr.Ghost" <[email protected]> wrote in
message
news:f060vi$npp$[email protected]..
> One of my friends advised me to develop my whole site on
the layout mode
> as its
> better than the standard as he says
> but I couldnot make an ordinary table with rows and
columns in th layout
> mode
> is there any one who can tell me how to?
> thanx alot
> -
How to create PDF with Form Builder (T-Code:SPF) and how to use it?
How to create PDF with Form Builder (T-Code:SPF) and how to use it? Is there anyone can show me some doc. or PA material ? << removed >> Thank you very much!!
Edited by: Rob Burbank on Nov 11, 2010 1:04 PMPDF forms also known as Adobe From or Interactive Forms.
Check this link -
Interactive Forms
REG:ADOBE FORM
Adobe forms
Regards,
Amit -
How to create folder with sub folder ?
How to create folder with sub folder ?
Hi,
Questions. 17 / 17 unresolved -> very bad reputation
but ok - let's help anyway ...
1. create everything in Screen Painter
2. set FromPane and ToPane property correct.
example:
Items in MainFolder: FromPane & ToPane: 1 to 3
Items in SubFolderA (From 2 To 2) - SubFolderB (From 3 To 3)
shouldn't be that difficult
in your Code set oForm.PaneLevel when the user clicks on the Folder
lg David -
Hello everybody,
It's my first time using Java Card ^_^,I want to create a file and fill the fill with binary data.but i don't know how to create file with APDU commands,so I need help here.
I think that there must be a Manual of the JavaCard's OS in this world,can someone tell me where to download it??
Thanks.
the fllowing is my card:
Samsung S1
Model:TiEx-32J
EEPROM size:32k
Platform Version:OP 2.0.1
Card Manager Status:OP_READY
KMC:40~4F/No derivation
Message was edited by:
AllenHuangIf you look around the forum for a bit, you will see that there is no notion of file systems on JavaCards (lexdabear posted this information less than two hours ago :-)). To store files, you will have to write an applet to hold byte arrays of the required size and handle receiving and sending of these.
As for documentation, you should have a look at the GP (General Platform) specification at http://www.globalplatform.org/, which defines communication between smart cards and other devices, as well as Sun's own JavaCard pages (http://java.sun.com/products/javacard/), which contain several useful resources on JavaCards.
Message was edited by:
Lillesand -
How to create Vector with reference to Collection
hello experts,
can someone let me know how to create vector with reference to Collection interface.
Collection is an interface. and we cant create an instance of it. i'm not clear of what to pass in that constructor.
Vector v = new Vector (Collection c);
what are the possible objects of 'c'
post some example code please.
thanksEver heard of reading the javadocs?
"Collection is an interface. and we cant create an instance of it." - you don't understand interfaces, then.
// I certainly can create a Collection - here's one
Collection c = new ArrayList();
// Now I'll add some Strings to my Collection.
c.add("foo");
c.add("bar");
c.add("baz");
// Now I'll make a Vector out of it.
Vector v = new Vector(c);% -
How do create query in SAP?
Dear Expert
How do create query report in SAP?
thanks for advancehi
this is to inform you that,
please follow the links:
http://wiki.sdn.sap.com/wiki/display/ERPFI/abap+query
http://wiki.sdn.sap.com/wiki/display/sandbox/ABAP+queries
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/40bec8da-4cd8-2910-27a9-81f5ce10676c?quicklink=index&overridelayout=true
hope this clears your issue
balajia -
How to create CATALOG with MS SQL Server?
Connection class has getCatalog(strCatalog) method. In order to use it, we must create CATALOG in Database?
How to create CATALOG with MS SQL Server?
Help me, please!!!You do not create these for any database, this is part of the Connection metadata.
The Catalog is the third level of table-like database object qualification as in "Catalog.Schema.Table". For SQLServer the qualification scheme is "Database.Owner.Table" and I would be surprised if they reported anything for the current connections getCatalog() method call.
What many people do is avoid table qualification altogether by setting the connection's context in a database proprietary manner and then keeping the SQL as clean as possible. For many ODBC and JDBC drivers this can be set in the configuration. For MS SQLServer you can also execute a "USE dbname" statement on the connection to avoid table qualification. -
How to create Query (Sq01) fro service contract
hi,
How to create Query for Service contracts , where i need to take a report for sub line items of that particular Service contract.
Ex: we maintain short text - services in the initial screen ,
in the next screen we maintain the sub line items for that short text (Activity numbers).
Please guide me on this.
Regards,Hi Sowmya,
1 Create User Group (SQ03)
Specify the users who should be authorized to run the query.
2.
Create Infoset (SQ02)
Indicates from which part of the SAP database the data is going to be retrieved and how the data is to be retrieved by the query.
3.
Create Queries (SQ01)
Create the query and arrange the layout
for joining the two tables there should be common field should be available in both the tables then only we can able to join the table and run the query
or use this below link
http://www.sap-img.com/abap/step-for-using-query-sq01-sq02-sq03.htm
Regards,
Pramod
Maybe you are looking for
-
Sony Mobile Indonesia: Bad Service Quality
Greetings to you all. My name is Giovan Pangku from Indonesia, an owner of Sony Ericsson Xperia ray ST18i. I am also a member of a facebook group, "Xperia Community", a group where we share everything about Xperia devices. On this thread, I'm going t
-
I don't want to restore photos from icloud onto my new iphone
Hi there, I had an iPhone 4 and just got a new 5c. I backed up my 4 to icloud as i dont't own a laptop. I bought 20GB of storage and everything seemed to work. When I set up new iPhone i selected 'Restore from iCloud Back up' as I need old contacts o
-
Getting the following Error when attempting to register a web provider: An error occurred when attempting to call the providers register function. (WWC-43134) An unexpected error occurred: ORA-29532: Java call terminated by uncaught Java exception: o
-
If statment based on details of Group
Post Author: bwells2 CA Forum: Formula I'm trying to create a If then statment and have the Value displayed on the group line. for example Group Detail I want to look of the group and find islike SCR then "Yes" else then "No" Thanks!
-
Buenas tardes, Mi problema es el siguiente: Cuando intento abrir una imágen cualquiera (jpg,png), no abre nada, es decir, sigo viendo la pantalla gris como si no hubiera hecho nada. Tengo windows 8 64 bits, por lo que instalé la versión para 64bits,