line count (*) the amount and add it to the previous of the resulting column
Hello
I'm new to sql and I want to create an additional column which allows to calculate the value of a row in the column number with the rank of its predecessor on the column of the sum. This is the query. I tried to use CUMULATIVE, but it does not serve the purpose.
select to_char(register_date,'YYYY-MM') as "registered_in_month" ,count(*) as Total_count from CMSS.USERS_PROFILE a where a.pcms_db != '*' group by (to_char(register_date,'YYYY-MM')) order by to_char(register_date,'YYYY-MM')
That's what I
registered_in_month TOTAL_COUNT
-------------------------------------
2005-01 1
2005-02 3
2005-04 8
2005-06 4
But what I would like to show is less than
registered_in_month TOTAL_COUNT SUM
----------------------------------------------
2005-01 1 1
2005-02 3 4
2005-04 8 12
2005-06 4 16
Hello
So all the ranks of the exit, you want a total cumulative up to and including this line. It's just that the analytical SUM function.
Here's one way:
SELECT TO_CHAR (TRUNC (hiredate, 'MONTH')
, 'fmMonth, YYYY ".
) AS registered_in_month
COUNT (*) AS total_count
, SUM (COUNT (*)) ON (ORDER OF TRUNC (hiredate, 'MONTH'))
AS total_so_far
FROM scott.emp
WHERE job! = "ANALYST."
GROUP OF TRUNC (hiredate, 'MONTH')
ORDER BY TRUNC (hiredate, 'MONTH')
;
I don't have a copy of your table, so I used scott.emp to illustrate.
I like the GROUP BY TRUNC (dt, 'MONTH') instead of GROUP BY TO_CHAR (dt,...) because it allows me to display in any format and always sort in chronological order.
For example, the output of the above query is:
REGISTERED_IN_M TOTAL_COUNT TOTAL_SO_FAR
--------------- ----------- ------------
December, 1980 1 1
February, 1981 2 3
April, 1981 1 4
May, 1981 1 5
June, 1981 1 6
September, 1981 2 8
November, 1981 1 9
December, 1981 1 10
January, 1982 1 11
May, 1987 1 12
Of course, YYYY-MM format works, too.
Tags: Database
Similar Questions
-
How to add an imaginary line in the result of the value of a SELECT statement.
Hello all-
I have requirment to add an imaginary line in the result set of a SELECT statement.
For example lets say it is a pay table having the following columns:
Number of Payment_id
status varchar2 (10)
number amount
date of payment_date
so here's the data: -.
Payment_id status amount payment_date
applied 1 100 12/07/2008
2 Reversed 200 01 / 06/2009
Applied 3 300 01 / 07/2009
Here is my SQL
Select * form payment where payment_date > = 01/01/2009
The output will be
2 Reversed 200 01 / 06/2009
Applied 3 300 01 / 07/2009
My desired output is less than
2 Reversed 200 01 / 06/2009
Applied 3 300 01 / 07/2009
reversed-200 2, 01 / 06/2009-(Dummy Row)
Third line here is the imaginary line that I add when the status is "reversed".
I would be very grateful for any help on this...
Thank you
GerardCartesion join against a shadow table is a useful method to create a fictitious line:
with my_tab as (select 1 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all select 1 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all select 1 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all select 2 cust_id, 1 Payment_id, 'Applied' Status, 100 Amount, to_date('12/07/2008', 'mm/dd/yyyy') payment_date from dual union all select 2 cust_id, 2 Payment_id, 'Reversed' Status, 200 Amount, to_date('01/05/2009', 'mm/dd/yyyy') payment_date from dual union all select 2 cust_id, 3 Payment_id, 'Applied' Status, 300 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all select 2 cust_id, 4 Payment_id, 'Reversed' Status, -400 Amount, to_date('01/06/2009', 'mm/dd/yyyy') payment_date from dual union all select 2 cust_id, 5 Payment_id, 'Applied' Status, 500 Amount, to_date('01/07/2009', 'mm/dd/yyyy') payment_date from dual), --- end of mimicking your table dummy as (select 'Reversed' col1, 1 rn from dual union all select 'Reversed' col1, 2 rn from dual) select mt.cust_id, mt.payment_id, mt.status, decode(dummy.rn, 2, -1*mt.amount, mt.amount) amount, mt.payment_date from my_tab mt, dummy where mt.status = dummy.col1 (+) order by mt.cust_id, mt.payment_id, dummy.rn nulls first; CUST_ID PAYMENT_ID STATUS AMOUNT PAYMENT_DATE 1 1 Applied 100 07/12/2008 1 2 Reversed 200 06/01/2009 1 2 Reversed -200 06/01/2009 1 3 Applied 300 06/01/2009 2 1 Applied 100 07/12/2008 2 2 Reversed 200 05/01/2009 2 2 Reversed -200 05/01/2009 2 3 Applied 300 06/01/2009 2 4 Reversed -400 06/01/2009 2 4 Reversed 400 06/01/2009 2 5 Applied 500 07/01/2009
Published by: Boneist on January 7, 2009 23:10
NB. You may need to mess around with the order if that is not in the order you want. You did not mention what the rules were for all orders expected, so I composed my own * {;-)Also, I added a (cust_id) identifier to differentiate different types of payments, as is usually the case. Remove unless it is not applicable to your case.
-
Insert a blank line in the result set
Hi friends,
SELECT * FROM EMPLOYEES ORDER BY DEPARTMENT_ID;
As a result of the foregoing, I need to INSERT a blank line in the result for each department_id. for example, the result should resemble the following:
EMP_ID - NAME - SALARY - DEPARTMENT_ID
101 - Albert - 10 000 - 10
102 - Benjamin - 8 000 - 10
103 - Chitra - 10 500 - 20
104 - David - 4 500-20
105 - Elango - 6 000 - 20
106 - faye - 6 000 - 30
107 - Ganga - 9 000 - 30
etc.
I don't want to insert into the table. I need a blank line just on the screen.
Thanks in advance.
Published by: James on March 8, 2010 11:37Something like this->
satyaki> satyaki>select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production PL/SQL Release 11.1.0.6.0 - Production CORE 11.1.0.6.0 Production TNS for 32-bit Windows: Version 11.1.0.6.0 - Production NLSRTL Version 11.1.0.6.0 - Production Elapsed: 00:00:00.00 satyaki> satyaki> satyaki>select m.empno, 2 m.ename, 3 m.sal, 4 case 5 when sal is null 6 and empno is null 7 and ename is null then 8 null 9 else 10 m.deptno 11 end deptno 12 from ( 13 select k.empno, 14 k.ename, 15 k.sal, 16 k.deptno 17 from ( 18 select empno, 19 ename, 20 sal, 21 deptno 22 from emp 23 ) k 24 union all 25 select t.* 26 from ( 27 select distinct null empno, null ename, null sal, deptno 28 from emp 29 ) t 30 order by 4 31 ) m; EMPNO ENAME SAL DEPTNO ---------- ---------- ---------- ---------- 7782 CLARK 2450 10 7839 KING 5000 10 7934 MILLER 1300 10 7566 JONES 2975 20 7369 SMITH 800 20 7902 FORD 3000 20 7876 ADAMS 1100 20 7788 SCOTT 3000 20 EMPNO ENAME SAL DEPTNO ---------- ---------- ---------- ---------- 7900 JAMES 950 30 7499 ALLEN 1600 30 7844 TURNER 1500 30 7654 MARTIN 1250 30 7521 WARD 1250 30 7698 BLAKE 2850 30 17 rows selected. Elapsed: 00:00:00.03 satyaki> satyaki>
Kind regards.
LOULOU.
-
Could not display the empty line in the results tab.
I have three columns.
Vendor revenue (Revenue) Count
during the 2nd column of income has no line, I am unable to see the Virgin, for example:
John | $200 | 2
Jack | || 0-> This column I a unable to show in my results tab.
Help, please.Just to be clear, the solution I provided is without having to touch the repository. Unfortunately, report designers often do not have access to the repository. However, I agree that there may be problems of performance according to the size of the request, etc. I assume that the user knows that if he has access to modify the repository, there are alternatives so that article of Rittman-Mead points out.
-
How to count the first column automatically.
Dear all.
I would like to calculate the first column from 1 to N, when the user clicks on the add a line button.
Please refer to the following
-------------------------------------- Code --------------------------------------
var nNodes is Test_Result1.sub_Product_accessories. Config_Acc.resolveNodes ("Config_Acc [*]"). Length;
If (nNodes < = 6) {}
Test_Result1.sub_Product_accessories. Config_Acc.instanceManager.addInstance ();
}AS-IS
AS IT WILL BE
Javascript code the Initialize event of the AccNum field:
this.rawValue = this.parent.index + 1
-
How to find the lines, where the second column only has a defined value
I have a table like
The data in the table can be as belowCREATE TABLE MY_MAP ( USERID NUMBER(10) NOT NULL, SYSTEMID NUMBER(10) NOT NULL, )
Now my requirement is to find all these IDS that are at systemid 6 but not at 9. That is to sayINSERT INTO MY_MAP VALUES(1,6); INSERT INTO MY_MAP VALUES(2,6); INSERT INTO MY_MAP VALUES(3,6); INSERT INTO MY_MAP VALUES(1,9); INSERT INTO MY_MAP VALUES(2,7);
2.3. [since 1 is both in the 6 and 9], should not be recovered.
I did two courses is a loop. Can someone give me a single query to do?SQL> select * from MY_MAP m 2 where SYSTEMID=6 3 and 0=(select count(*) from MY_MAP m2 where m2.USERID=m.USERID and m2.SYSTEMID=9); USERID SYSTEMID ---------- ---------- 3 6 2 6
or
SQL> select * from MY_MAP m 2 where SYSTEMID=6 3 and NOT EXISTS (select 1 from MY_MAP m2 where m2.USERID=m.USERID and m2.SYSTEMID=9); USERID SYSTEMID ---------- ---------- 3 6 2 6
or
SQL> select * from MY_MAP m 2 where SYSTEMID=6 3 and userid not in (select userid from MY_MAP m2 where m2.SYSTEMID=9); USERID SYSTEMID ---------- ---------- 3 6 2 6
or
SQL> select userid 2 from MY_MAP 3 where SYSTEMID in (6,9) 4 group by userid 5 having sum(decode(SYSTEMID,9,1,0))=0; USERID ---------- 2 3
Max
http://oracleitalia.WordPress.comPublished by: Massimo Ruocchio March 1, 2010 10:43
-
Query Oracle - to display the line in the Condition column in function.
Hi all
I have data like below.
ID of ranking name Desc
========================
1 ID1 A AA1
2 ID1 A AA2
1 ID1 B BB1
2 ID1 B BB2
1 ID2 C CC1
2 ID2 C CC2
1 ID2 D DD1
2 ID2 D DD2
I need the query to retrieve the data as below.
ID of ranking Name1 Name2
==================================
ID1 1 A - AA1 B - BB1
1 ID2 CC1 - C D - DD1
That is to say) Condition: Grade must be 1.
Thank you and best regards,
Stéphane.
with
DATA_TABLE as
(select 1 Rank, ID 'ID1', 'A' name, Descr "AA1" of union double all the)
Select 2, 'ID1', 'One ', ' AA2' Union double all the
Select 0, 'ID1', 'B', "BB1" dual union all
Select 3, 'ID1', 'B', 'BB2' from dual union all
Select 2, 'ID2', 'C', 'CC1' from dual union all
Select 3, 'ID2', 'C', 'CC2' from dual union all
Select 1, 'ID2', would be ', 'DD1"dual union all
Select 3, 'ID2', would be ', 'DD2' from dual
)
SELECT id, Name1, name2
go (select id,
name_desc_rank,
ROW_NUMBER() over (partition by order of identification by name_desc_rank) rn
go (select grade,
ID,
name | '-' || descr | '-' || TO_CHAR (Rank) name_desc_rank,
ROW_NUMBER() over (partition by order of rank identification) rn
of data_table
)
where rn<=>=>
)
Pivot (Max (name_desc_rank) of rn (1 as name1, name2 2))
ID NAME1 NAME2 ID1 A-1 AA1 B-BB1-0 ID2 C CC1-2 D DD1-1 Concerning
Etbin
-
get the only the lines that the max column
Hello
This is my entry
Thanks in advance for any help2 x1 18/03/2003 59,4 2 x1 03/04/2003 55 2 x1 01/01/2002 51,65 33 y1 22/08/2005 44 61 z1 22/08/2005 55 61 z1 01/01/2008 55 64 z2 16/01/2004 44 64 z2 22/08/2005 44 How can I do to get only the rows having the max data_iv, that is: 2 x1 03/04/2003 55 33 y1 22/08/2005 44 61 z1 01/01/2008 55 64 z2 22/08/2005 44
You can use the analytical functions with a view online, for example
SELECT * FROM ( SELECT col1 , col2 , col3 , col4 , RANK() OVER (PARTITION BY col1 ORDER BY col3 DESC) ranking FROM table ) WHERE ranking = 1
-
Add lines to the query result?
Is it possible to add lines to the result of a shutdown of the SQL query, similar to the CALCULATION command in SQL * more?
In other words, for example, when A column value changes, add a line after the previous line (the last one before changing the column A) to display the sum of the values in column B.
for example
< PRE > A and B
- --
1 3
1 4
1 5
12
2 9
2 1
2-7
1 < / PRE >SQL> create table sales (person,city,sales) 2 as 3 select 'Alice', 'Phoenix', 19 from dual union all 4 select 'Alice', 'Tulsa', 11 from dual union all 5 select 'Bob', 'Phoenix', 17 from dual union all 6 select 'Bob', 'Tulsa', 9 from dual union all 7 select 'Tony', 'Miami', 5 from dual union all 8 select 'Tony', 'San Francisco', 4 from dual union all 9 select 'Tony', 'San Francisco', 3 from dual 10 / Tabel is aangemaakt. SQL> select case grouping_id(person,city,rowid) 2 when 1 then 'Sub-Total for' 3 when 3 then 'Sub-Total for' 4 when 7 then 'Grand Total' 5 end notes 6 , person 7 , city 8 , sum(sales) sales 9 from sales 10 group by rollup(person,city,rowid) 11 having grouping_id(city,rowid) != 1 12 or count(*) > 1 13 order by person 14 , city 15 , grouping(rowid) 16 / NOTES PERSO CITY SALES ------------- ----- ------------- ---------- Alice Phoenix 19 Alice Tulsa 11 Sub-Total for Alice 30 Bob Phoenix 17 Bob Tulsa 9 Sub-Total for Bob 26 Tony Miami 5 Tony San Francisco 4 Tony San Francisco 3 Sub-Total for Tony San Francisco 7 Sub-Total for Tony 12 Grand Total 68 12 rijen zijn geselecteerd.
Kind regards
Rob. -
Satellite P30-110: vertical lines on the screen - Virus?
I have a 110 - p30 and emerged recently vertical on my screen I have run norton AV and nothing was found is a possible virus any help appreciated because I don't want to lose all my work.
Hi Dave
If you don't want to lose your work trial to save on a way you like it (data CD/DVD or copy files on the external HARD disk device).
I don't really know if the vertical lines are the result of some viruses, but I believe some hardware malfunction can be responsible for this. Just detailed test can give more answers. In your case the best solution is to backup all important data and preinstall the device with the recovery media. On this way the unit will be own pre-installed and you can check if the lines happen.
If so, there are certainly a hardware problem. Sorry, but in this way it is not easy to give you more answers. Please back up your data. If the problem will be much worse than what you have a big problem.
-
Click on search for result code doesn't display the line containing the search results
I use the latest version of DreamweaverCC2014 on the latest version of Mac Mavericks. I use Dreamweavers find and replace to find code in an open html document. In the search results Panel results aren't clicking on me at the relevent code line in the document. It used to work well in the previous version of DW, I was using.
In the DW help note it is said: ' display the results of a particular search in context: select window > results to display the search panel. " Double-click on a line in the search panel. If you are looking for the current file, the Document window displays the line containing that search result. ' http://helpx.adobe.com/Dreamweaver/using/Text.html#search_for_and_replace_text
Double-click does not display the line containing the result of the search for me. It seems to work OK in my CSS files, but not in HTML longer (1010 lines).
Any advice? Someone at - it the same problem? Thank you
I have the same problem with all the HTML files that have external style sheets. for example .
So it seems to be a bug around that. When you delete the above, double click functionality works.
-
Small black lines on the sides of the integrated video Youtube
I joined a number of youtube videos in a simple html doc. Most of them seem to be good, but there are 2 has a slight black line on some of the edges. I really need them to be crispy like the others. The video on YT doesn't have those same black lines. Anyone know how to remove these?
http://www.intellicom-analytics.com/jcuundergrad.html (The right side of the first video and both sides of the last video)
Note: I am not owner of the videos YT incorporated is not possible to change them at this end.
Thanks in advance!
The black lines are the result of a mistake in setting the original size video/video proportions. And these line are visible in the original YouTube videos... especially a problem in the image of "post" that appears before the beginning of the video. See here:
http://www.YouTube.com/v/y5uVqOuMdCw?version=3&autohide=1&showInfo=0
and here:
http://www.YouTube.com/v/na1e9uLImIU?version=3&autohide=1&showInfo=0
The lines have nothing to with your video player on your page or you can correct it by changing your Web page... the lines are part of the video itself.
To correct this problem, you must perform a new rendering of the original video file... NOT the Youtube file, but the original.
If the player holds the original aspect ration (width to height), the video will be resized to fit the dimensions of the player... but if the player is not big enough or wide enough... the black bars appear... that aren't black bars but space empty that the video did not cover. Black bars on the sides of the clip mean that the size of the screen is not big enough. Black bars on the top/bottom, means that the screen is not wide enough.
These black space "bar" can also be introduced during the editing process if the dimensions of the screen are not properly defined... which seems to be the case here video moose.
Best wishes
Adninjastrator
-
Highlighting the lines of State based on the results of the report
Hello! I think it's an easy question, but I have not found an answer for her through the forums looking. Is there a way to highlight or change the colors of some dependent lines on the result set data? I'm trying to display transaction data of the customer for call center agents and highlight some rows based on the values in the results...
Thank you very much!You can view a customized report (column model) model - they give you 4 places for the conditions. Here is an example:
Column Template 1:
#COLUMN_VALUE# Column Template 1 Expression: '#1#' like '%Total%'#1 # being the first column in your results. This isn't bad if you only need 4 conditions and know the placement of your fields - you just configured different look and feels in your CSS and change the class according to the criteria.
Here's another way:
http://Apex.Oracle.com/pls/OTN/f?p=11933:7Hope that helps...
-
Delete the entire column (of an array) If you have specific words
Can someone help me?
I have a document of great size with plenty of tables.
The tables have the same structure:
a line with the title and under different columns, where the latter is a price list.
The first word of this last column is the PRICE, and we need, is that all cells (with content) that are below this cell to be eliminated PRICES...
I tried to do with this: https://forums.adobe.com/thread/1533114?q=delete%20rows
but the first abolition of PRICE all the words, but with this script are the lines, not the deleted columns...
Can someone help me?
Thanks in advance!
Try this,
var doc = app.activeDocument, _cells = doc.stories.everyItem().tables.everyItem().cells.everyItem().getElements(); for ( var k = _cells.length-1; k>= 0; k-- ) { try{ if ( _cells[k].contents == "PRICE" ) _cells[k].columns[0].remove(); }catch(e){}; }
-
The result collection has exceeded the maximum flood control level?
Hi all
When you run a metric on an agent, I get the following message:
Someone at - it any information on that?The following exception has occurred: RTMCollection: exception occurred: java.lang.UnsupportedOperationException: Collection Result Maximum Flood Control Level Exceeded
This measure could go back a few thousand lines in the result, so I added the "LIMIT_TO" in the file default collections:
However, the error is still happening...<MetricColl NAME="......."> <LimitRows LIMIT_TO="1750"/> </MetricColl>
1. someone comments on the flood control message?
2. should what nr of lines I introduce LIMIT_TO?
Any comment is very appreciated!
Thank you
EdFlood control settings are different from the concept of Limit_to - the concept of limit affects the output of the metric. flood control settings protect the agent against a metric producing too many lines that could theoretically allow the failure of the agent.
So first of all, I would seriously consider the metric measures reports that more than 10,000 lines are ill-conceived likely metric.
In order to control the parameters of flood control, they can be adjusted if necessary for testing purposes, but I wonder again seriously any metric design requiring a large volume. The parameters are:
/**
flood control data to control the number of rows may result in collection
* keep. from the min, we will open a session but rejects silently new upcoming lines
* in the result set. If we reached the maximum, the assumption is that the
' * ' fetchlet ' is out of control (loop?) and we will report a duration
* statement.
*
* @name CollectionResults.MaximumRowsFloodControlMin
* @type integer
* @unit lines
* @default 5000
*/
private static final ConfigPropertyMAXIMUM_ROWS_FLOOD_CONTROL_MIN =
() Config.newIntProperty
"CollectionResults.MaximumRowsFloodControlMin,"
5 000)./**
flood control data to control the number of rows may result in collection
* keep. from the min, we will open a session but rejects silently new upcoming lines
* in the result set. If we reached the maximum, the assumption is that the
' * ' fetchlet ' is out of control (loop?) and we will report a duration
* statement.
*
* @name CollectionResults.MaximumRowsFloodControlMax
* @type integer
* @unit lines
* @default 10000
*/
private static final ConfigPropertyMAXIMUM_ROWS_FLOOD_CONTROL_MAX =
() Config.newIntProperty
"CollectionResults.MaximumRowsFloodControlMax,"
10000);and can be controlled via:
emctl setproperty agent-allow_new-name-value...
or by the emd.properties implementation and performing an emctl reload.
Maybe you are looking for
-
Satellite C855-2J4 - impossible to pass to Win 8.1 - error 0 X 1900101 0 x 30018
Hello I've been trying for days to upgrade my mam laptop, but I have unsuccessfully... Tried everything, followed the instructions of Toshiba: 'how Upgrade "... BUT I does not work... I'm always ending with the same error message...1900101 X 0 0 x 30
-
Dear All > help me pleas I have problem to the question of security on my iPhone only no email comes to my rescue or recovery email to reset for them its important to me just because I'm fried there's someone hacking my i cloud using my game Center a
-
computer keeps restarting, against all odds, while I browse the internet
How can I determine my type of memory to change? My computer keeps restarting, against all odds, while I browse the internet, I have advised me to try to change the memory card, but I do not know how to determine the type of card, I need. I have a Mi
-
I haven't changed any settings yet all programs and Web sites on the internet and offline display extra-large onmonitor two horizontally and vertically which makes it unable to see the entire screen which can make?
-
What is the best option to place text in a specific area of a bitmap image. The text should be an event affiliated with her listener. Any code, or tips tutorial would be great. Thank you