Calculate the difference based on the values of 2 different columns
Hello friends,I basically want to do something like below that is the Format t - SQL:
SUM (CASE column WHERE 'ABC' THEN 1 ELSE 0 END)-SUM (CASE columnB WHERE 'XYZ' THEN 1 ELSE 0 END)
For which I was changing the following code in Oracle:
SUM (CASE column = 'ABC' THEN 1 ELSE 0 END)-SUM (CASE columnB = END ELSE 0 'XYZ', 1).
But his failure to validation with an error message - missing right parenthesis...
Rest of the qry is very good, and each time I have add this line it starts failing.
Published by: Sweta on 11-Sep-2009 09:32
Try this
SUM (CASE
WHEN columna = 'ABC'
THEN 1
ELSE 0
END)
- SUM (CASE
WHEN columnb = 'XYZ'
THEN 1
ELSE 0
END)
or
COUNT (CASE
WHEN columna = 'ABC'
THEN 1
END)
- COUNT (CASE
WHEN columnb = 'XYZ'
THEN 1
END)
Note: you can use this sythax in oracle
SUM(CASE columnA WHEN 'ABC' THEN 1 ELSE 0 END) - SUM(CASE columnB WHEN 'XYZ' THEN 1 ELSE 0 END)
Example of
SELECT emp_test.*,CASE ename
WHEN 'SCOTT'
THEN 1
END ind
FROM emp_test
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO IND
---------- ---------- --------- ---------- ---------- ---------- ---------- ---------- ----------
7369 SMITH CLERK 7902 1980-12-17 800 20
7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30
7521 WARD SALESMAN 7698 1981-02-22 1250 500 30
7566 JONES MANAGER 7839 1981-04-02 2975 20
7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30
7698 BLAKE MANAGER 7839 1981-05-01 2850 30
7782 CLARK MANAGER 7839 1981-06-09 2450 10
7788 SCOTT ANALYST 7566 1987-04-19 3000 20 1
7839 KING PRESIDENT 1981-11-17 5000 0 10
7844 TURNER SALESMAN 7698 1981-09-08 1500 30
7876 ADAMS CLERK 7788 1987-05-23 1100 20
7900 JAMES CLERK 7698 1981-12-03 950 30
7902 FORD ANALYST 7566 1981-12-03 3000 20
7934 MILLER CLERK 7782 1982-01-23 1300 10
14 rows selected.
Tags: Database
Similar Questions
-
To build the waveform.vi function how to calculate the value of dt
Dear all
Please guide me How to calculate the value of dt according to waveform.vi of construction
My sampling rate is 25000 and I take 200000 samples.
Kind regards
Muhammad Irfan
It's all simple arithmetic. The inverse of the sampling frequency power of samples is then the dt or the time between samples the number of samples is not relevant.
-
Process of calculation to calculate the value after submit after all validations
Hello
Please help with a possible approach or suggestions for the calculation process.
I have a calculation process after submit I want to calculate its value after that all validations are handled. Because this process of calculating trim is off of the first part of the input string of the user for the P3_USES element. Thus, for example consider; the user selects a value for P3_USES (point list manager) to be "TAC"... BCA... BCA... BCA... 0.CA BC... "CA IT BC. So my calculation process just stripes off the coast of the first portion of the string and computes the value will be "BCA"... BCA... BCA... 0.CA BC... "CA IT BC. It works fine when all postings on the page are placed without cooking.
The problem occurs, then the validation fails on the form. Once the validation fails, the calculation process; already calculates the value and the P3_USES value form element is set to "BCA"... BCA... BCA... 0.CA BC... "CA IT BC. So, here the user solves the problem of validation and sends it again the form, but at this point the value is calculated again but this time that my string is "BCA"... BCA... BCA... 0.CA BC... CA IT BC"which is not correct, because my initial user string entry was"TAC"... BCA... BCA... BCA... 0.CA BC... "CA IT BC.
So my question is how they treat the value of my calculation after all validations. While I can keep the original value of the P3_USES element. I'm using the version of Oracle APEX 4.0 and Oracle 10 g R2 database.
Thank you
Rambeau
Hello
Combine code of calculation and validation?
Perform the calculations in the process?
Use another element to contain the value 'real '?
Kind regards
Jari
-
Calculate the value based on the selection of the checkbox
People from g ' Day,.
I have myself a little stuck on a job that I have here, this javascript Gets the better of me.
The idea is that this script takes the total sub and adds a surcharge for credit card (in percentage) based on a selection of the checkbox, then spit out the value to be entered in another field.
If someone could have a quick look over what follows and let me know where I went wrong, it would be appreciated.
---
Subtotal var = this.getField("SubTotal").value;
var mastercardTick = this.getField ("MasterCard");
var visaTick = this.getField ("Visa");
var amexTick = this.getField ("Amex");
Var extra = this.getField("CreditSurcharge").value;
card credit var = this.getField("PayCredit").value;
If (creditcard.value = 'Off') {}
Event.Value = 0;
} else {}
If (mastercardTick.value = 'Yes') {}
overload. Value = (1,2 / 100) * subtotal.value;
} ElseIf (visaTick.value = 'Yes') {}
overload. Value = (1,2 / 100) * subtotal.value;
} ElseIf (amexTick.value = 'Yes') {}
overload. Value = (3.75 / 100) * subtotal.value;
} else {}
Event.Value = 0;
}
}
---
For lines like these:
overload. Value = (1,2 / 100) * subtotal.value;
If it should not be as:
Event.Value = (1,2 / 100) * subtotal.value;
The variable supplement is defined at the beginning of the script to the value of the field, so the surcharge.value parameter is not any sense.
-
Calculate the value of the field based on the value of the user input field
Hi all
We use a BPM 11.1.1.5.0 with feature pack. We have BPM form which has five fields all the text in the input field. The user will enter any amount in these fields. We have another field in the form that displays the sum of the field all five. This should add the input value dynamically when the user navigates out of a field.
I'm not able to think how I can achieve this. It is valuechangelistener I need code. Should I use a java code to get the value of the entry field and make the calculation in the java code and then assign it to the output field? or is there an option/BPM feature that allows to avoid java coding.
Thanks in advance
Sachin GuptaAdd this as an idea because you asked how this could be done without Java code.
If all five digital and no other item reference fields cannot be empty or null, you can:
(1) for each of the 5 numeric fields, expand the section "Behavior" property and set their properties Autosubmit true. As you look at each of the 5 areas, note the text in each of their property 'Id '.
(2) for the numeric field (I'll call it the "SumValue" field), you added that you want to add the other fields, expand the "behavior" property section-> click the arrow to the right of the property 'PartialTriggers'-> in the transfer dialog box that comes up, select each of the 5 areas (those you find the ID of the first step) and their shuttle above the selected list-> click OK-> look at your PartialTriggers for the field of SumValue property - it should now display the ID 5 with spaces between them.
(3) open each of the 5 areas and copy the text in each of their properties 'Value' (e.g. #{bindings.) Salary1.inputValue}) and paste this text for each of the 5 text fields in your text editor in a text-> if editor is
#{bindings.Salary1.inputValue} #{bindings.Salary2.inputValue} #{bindings.Salary3.inputValue} #{bindings.Salary4.inputValue} #{bindings.Salary5.inputValue}
to take
#{bindings.Salary1.inputValue+bindings.Salary2.inputValue+bindings.Salary3.inputValue+bindings.Salary4.inputValue+bindings.Salary5.inputValue}
(4) select the field 'SumValue'-> again in the property Panel, delete the text in the field 'Value'-> paste the text you created in your text editor in the 'Value' property of the field SumValue.
-
Calculate the values in the table
I have a table with several lines. have 2 input text in each row of the table. In the same vein, there is a field (outputText) whose calculation is based on the insertion of data from the other two.
the calculation is performed correctly.
the problem occurs when I have more q a row in the table. If you have 3 lines, for example, are calculated for a line (not being not not the first) to the other lines that this field is null / empty.
I think that it does not have the iterator. Anyone help me?
Hi user,
Calculate the difference using the class viewrow for more information
Look at the blog below could help ful
Andrejus Baranovskis Blog: Column calculated in ADF Faces component af:table
-
Adobe Acrobat Standard DC - calculate, the value is the "sum" of
The "text field properties / calculate / value is the 'sum' of the following fields / pinch / field selection"window does not provide any options to select. " I formatted all the fields in the source & field sum as 'number' and out spaces in domain names. My version of Acrobat Standard DC excludes a Sum function? Thank you, all!
It displayed fine. It looks good, so I don't know why there is no fields displayed when you click the button to 'Pick '. I always use the JavaScript option, but you can try the option of simplified field notation to work around the problem. You need to enter something like:
Field1, Field2, field3 and field4
Where are the names of the fields that you want to calculate the total, so change to match your domain names.
-
Web Forms: Deleting line based on the value of a specific column
Hello
I have an online form in which I want to apply delete missing on the ranks, but only on the value of the first column. So, if the first column is #missing I want the deleted row, even if the columns are given in it.
Is it possible to do this?
I'm on ver 11.1.2.2 Hyperion Planning
Shehzad
Published by: shehzad k on January 24, 2013 11:51Unfortunately, no. There is no way to add the delete line based SOLELY on the existence of a value in the first column. It would be nice to see some of the more advanced features "conditional delete", we en flies over to the planning of the entry forms.
You can do the "clumsy" things with data validations where you gray - out ranks in view of the existence of a value in a particular cell, however while this might SUGGEST that the user should not enter data in a particular line, it would not PREVENT to do so.
We have seen many improvements in form lately with the introduction of data validations. I hope the momentum continues.
-Jake
-
How to calculate the value of the parameter in siebel.
Hi all
I am new to this world of siebel.
I want to set the value of my settings.
How I calculate that which is appropriate and value which is the maximum for the parameters.
Thank youI assume you mean Max and Max MT Server tasks.
Please read the following on Supportweb: how to set the parameters of Max and Max MT Server tasks for the object Siebel Manager? [476018.1 ID]
-
query to calculate the value and produce new lines
QUARTER CUSTOMER PRODUCT RETAIL_SALES_AMT WHOLESALE_AMT
01/01/2006 ABC VACUUM CLEANER 454234,00 65633456.00
01/04/2006 ABC VACUUM CLEANER 324562,00 45333234.00
01/07/2006 ABC VACUUM CLEANER 67845423.00 NULL
01/10/2006 ABC VACUUM CLEANER 67453453.00 NULL
01/01/2007 ABC VACUUM CLEANER 56754633.00 NULL
01/04/2007 ABC VACUUM CLEANER 45423434.00 NULL
Hi guys,.
It's a situation where I have to produce a few new lines with projections based on Q4 RETAIL_SALES_AMT
RETAIL_SALES_AMOUNT and fourth ' rs following WHOLESALE_AMT. As you can see from the sample data for a specific customer,
product I have populated only until 01/04/2006 retail_sales_amt but WHOLE_SALE amt for the same product and customer
are there up to 01/04/2007.
I have to produce a PROJECTED RETAIL_SALES_AMT and it must be inserted in a new line with an indicator to identify
a proposed line. Here, in this case I have to produce a new line of projection from 07/01/2006,10/01/2006 and 01/01/2007
the RETAIL_SALES_AMT. The method of calculation is provided for in:
retail_sales_amt scheduled for 07/01/2006=.345+ ((01/07/2006 whole_sales-01/04/2006 whole_sales) / (01/04/2006 whole_sale)))
* 01/04/2006 RETAIL_SALES_AMT and move forward to subsequent quarters.
Is it possible that I can use a query to produce these new lines by calculating the RETAIL_SALES_AMT on the fly, or any other
How to procedure.
Please help as it seems a little complicated.
Concerning
Published by: user626688 on October 27, 2009 11:26
Published by: user626688 on October 27, 2009 11:26
Published by: user626688 on October 27, 2009 11:27
Published by: user626688 on October 27, 2009 11:28
Published by: user626688 on October 27, 2009 11:31
Published by: user626688 on October 27, 2009 11:32Hello
As far as I can tell, that's what you asked for:
WITH got_prev AS ( SELECT table_x.* , LAG (wholesale_amt) OVER ( PARTITION BY customer , product ORDER BY quarter ) AS prev_wholesale_amt FROM table_x -- WHERE ... -- Any filtering goes here ) , tree AS ( SELECT got_prev.* , SYS_CONNECT_BY_PATH ( CASE WHEN LEVEL = 1 THEN retail_sales_amt ELSE ( .345 + wholesale_amt - prev_wholesale_amt ) / prev_wholesale_amt END , '*' ) AS path FROM got_prev START WITH retail_sales_amt IS NOT NULL CONNECT BY retail_sales_amt IS NULL AND quarter = ADD_MONTHS (PRIOR quarter, 3) AND customer = PRIOR customer AND product = PRIOR product ) SELECT quarter , customer , product , COALESCE ( retail_sales_amt , eval_number ( LTRIM ( path , '*' ) ) ) AS retail_sales_amt , wholesale_amt , NVL2 ( retail_sales_amt , 'F' , 'T' ) AS projected_flag FROM tree ORDER BY customer , product , quarter ;
I posted earlier the eval_number function.
In this query, a group of consecutive quarters, where the first group a retail_sales_num and the rest of the members of the group are not, is treated as a hierarchy. The retail_sales_amt of all members (except the first) will be based on the previous, as well as the wholesale_amts past and present.
Say that a tree is 5 points of time (as in your examples of data). We can calculate the 2nd point in several ways: using analytical functions, for example. But we cannot use the same formula to calculate the 3rd point, because the calculation of section 2 must be completed before we can calculate the 3rd. It goes the same for the 4th and 5th.
This is CONNECT BY arrives. CONNECT BY is one thing in Oracle SQL that can be recursively; children may find themselves once their parents are found, in the same way we want to calculate the nth retail_sales_amt once the amount of the n-minus-1 has been calculated. To do this, we use SYS_CONNECT_BY_PATH, where the first element in the path is the retail_sales_amt given, and all others are the factor to multiply this number to get the next amount.
SYS_CONNECT_BY_PATH produces a string like ' * 324562 *. 4965935 *-. 0057739', which should be interpreted as a number. TO_NUMBER won't: TO_NUMBER cannot convert only a single numeric literal. Instead, we have a function defined by the user who put this string dynamically in the SELECT clause of a query, where it is interpreted as a numeric expression. -
Is there a way to dynamically calculate the values for the IN operator?
I want to know if there is a way to dynamically calculate the criteria to include within an IN operator in the WHERE clause. "For example when I try to run the following I get an Oracle error message ' OR!-01722: invalid number." The script below is just an example to help illistrate the problem, I don't want to hardcode the values assigned to the v_test directly within the IN operator because the values of v_test will change from user to user.
DECLARE
v_test VARCHAR2 (10): = '1,15,25,55';
v_tmp VARCHAR2 (50): = NULL;
BEGIN
SELECT d.metric_title IN the tbl_health_metric_definition v_tmp d
WHERE d.metric_status = 'Active' AND d.metric_id IN (v_test);
END;You can convert the string "1,15,25,55" online like this
SQL> select regexp_substr('1,15,25,55' ,'[^,]+', 1, level) list 2 from dual 3 connect by level <= NVL( LENGTH( REGEXP_REPLACE( '1,15,25,55' , '[^,]+', NULL ) ), 0 ) + 1 4 / LIST ---------- 1 15 25 55
and use this selection in your IN clause.
-
Calculate the values of a SharePoint workflow status Page column lines
On the workflow status page, how can I have a column with a value in the column lines? My workflow page lists commands that are in the workflow. I wish there was a column where the value of each PO, displays a running total of the PO rises before him.
Hello
It is not a community forum for issues of SharePoint. Please post to the appropriate
Forum on MSDN SharePoint.
http://social.msdn.Microsoft.com/forums/SharePoint/en-us/home
Don
-
Hi gurus
I'm stuck on 1 Scenario and need your help. I have the following table:
Create table
drop table age_rate;
CREATE TABLE age_rate
(
age_0_4 number 4,
age_5_20 number 4,
age_21_34 number 4,
age_35_44 number 4
);-------------------------------
Insertion
INSERT INTO age_rate
SELECT 45, 50, 60, 90 double UNION ALL
SELECT 45, 50, 60, 88 OF double UNION ALL
SELECT the 40, 50, 60, 90 double UNION ALL
SELECT 5, 50, 60 and 88 DOUBLE;
-------------------------------
Query on table
SELECT * from age_rate;
The query result
age_0_4 age_5_20 age_21_34 age_35_44
45 50 60 90
45 50 60 88
40 50 60 90
5 50 60 88
Power required
Rate Min_age Max_age
-The lower is age band 0_4
45 0 4
45 0 4
40 0 4
5 0 4
-The lower is age band 5_20
50 5 20
50 5 20
50 5 20
50 5 20
-The lower is age band 21_34
60 21 34
60 21 34
60 21 34
60 21 34
-The lower is age band 35_44
90 35 44
88 35 44
90 35 44
88 35 44
Rules
-I have all the data in the rows each column online create separate lines and add 2 columns automatically Min_age and Max_age and insert the value on these columns based on the name of the column for example if the column name as age_0_4 then insert 0 in min_age and 4 in max_age means values for Min_age and Max_age extracted from the base of the column name. I don't know if it's possible or not, but I appreciate if someone can give me the solution for this problem... Do you like answers. Thank you
Hello
I'm not 100% sure what you want. Do you want 16 production lines at a time, which is 4 lines of output for each line that is actually in the table?
This looks like a job for the UNPIVOT operator:
SELECTION rate
min_age
Case min_age
WHEN 0 THEN 4
WHEN 5 THEN 20
WHEN 21 AND 34
WHEN 35 THEN 44
END AS max_age
Of age_rate
UNPIVOT (rate
FOR min_age IN (age_0_4 0)
age_5_20 AS 5
age_21_34 AS 21
age_35_44 AS 35
)
)
ORDER BY min_age
;
-
What SYS (or tables) store the value of a spec /not/ NULL columns? (It doesn't seem to be COL$)
NOTE: This is NOT a trick question - although it seems to be.
Test configuration:
Test configuration:BANNER Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production
1. a table is created by SCOTT in the SCOTT schema with a NULLABLE column.
2. a primary key constraint is added using only the NULLABLE column
3. Requests for information on USER_TAB_COLS, ALL_TAB_COLS, DBA_TAB_COLS and SYS. COL$ see NOT NULL for the column NULLABLE
as necessary for a primary key constraint. Views derive their data from the column of $ NULL the sys. Table of $ COL
using
and the table of $ COL shows a numerical value of '0' before you add the primary key and a value of "1" later.'DECODE (SIGN (c.null$), -1, 'D', 0, 'Y', 'N'),
4. a query on the DDL metadata table shows the specification for column NULLABLE of origin involved.
Question - where this original specification NULLABLE is stored?
This question is based on a question asked by another user in this thread
Columns becoming nullable after a fall of primary key?
I created the following specially for that matter test case
The DOF shows that Oracle keeps the original spec NULLABLE for the column and uses it to generate the DDL orginal, even if there is a primary key on the table and the system views (and COL$) show the column non NULLABLE.-- scott ensures table does not exist DROP TABLE tbl_test CASCADE CONSTRAINTS; -- scott creates a table CREATE TABLE tbl_test ( col_1 NUMBER, col_2 NUMBER NOT NULL); -- scott queries to check the the column nullable status SELECT table_name, column_name, nullable FROM user_tab_cols WHERE table_name = 'TBL_TEST'; -- TABLE_NAME | COLUMN_NAME | NULLABLE -- TBL_TEST | COL_1 | Y -- TBL_TEST | COL_2 | N -- Scott addes a primary key constraint using only the nullable column ALTER TABLE tbl_test ADD CONSTRAINT tbl_test_pk PRIMARY KEY(col_1); -- scott queries to check the the column nullable status SELECT table_name, column_name, nullable FROM user_tab_cols WHERE table_name = 'TBL_TEST'; TABLE_NAME,COLUMN_NAME,NULLABLE TBL_TEST,COL_1,N TBL_TEST,COL_2,N -- scott queries to get the table DDL select dbms_metadata.get_ddl('TABLE', 'TBL_TEST', 'SCOTT') FROM DUAL; DBMS_METADATA.GET_DDL('TABLE','TBL_TEST','SCOTT') CREATE TABLE "SCOTT"."TBL_TEST" ( "COL_1" NUMBER, <------ where is this NULLABLE spec stored? "COL_2" NUMBER NOT NULL ENABLE, CONSTRAINT "TBL_TEST_PK" PRIMARY KEY ("COL_1") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS NOCOMPRESS LOGGING TABLESPACE "USERS" ENABLE ) SEGMENT CREATION DEFERRED PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING TABLESPACE "USERS"
So where is the original information NULLABLE actually stored?rp0428 wrote:
What SYS (or tables) store the value of a spec /not/ NULL columns? (It doesn't seem to be COL$)I think that it becomes a bit messy depending on order of activity:
You can see Col. .null$ is set to a non-zero when the desrcibe command displays the column as not null, but it can happen for two reasons:
(a) user sets the column as not null - in which case you get a line in cdef$ with type # = 7
(b) the user adds a primary key to table - in which case you get a line in cdef$ with type # = 2If you declare null AND add a primary key, you get two lines - that's why it is possible for Oracle to determine if he should remove the flag not null when you remove the primary key and also allows dbms_metadata show the create statement of table without a NOT NULL even when describe it the watch with a NOT NULL - dbms_metadata can respond to the presence of the type # = 2 and absence of the type # = 7.
Concerning
Jonathan LewisBy the way: by a strange coincidence, it seems to me answering the previous post, three days before it was asked: http://jonathanlewis.wordpress.com/2012/04/19/drop-constraint/#comment-46140 (on the doubts, this isn't - it answers a different question on the removal of constraints).
Published by: Jonathan Lewis April 23, 2012 11:07
-
Default value in always different columns in the comparison tool
Hi all
I generated a script of my model, in this script, I have a few columns with a default value,
After that I tried to compare with the import/datadictionary permutation model target my datamodeler with my database model,
but for all the columns that I've set the default, I found differences, when I check that the values are identical except for the space at the end of the value.
I checked the script and it's the row of the column:
LAST_MOD_TS DEFAULT SYSTIMESTAMP TIMESTAMP NOT NULL
AS you can see in the line is a double space between SYSTIMESTAMP and NOT NULL,.
This double space generates a default 'SYSTIMESTAMP' to the column value and the comparison tool is good then it's a difference,
but this difference is generated by the double space generated by the Publisher of the DOF.
I don't know if I can change something in my configuration of the tool to solve the problem,
Thanks in advanceHello
Thanks for reporting this problem. I connected a bug on this issue.
David
Maybe you are looking for
-
my itunes is going to mix one song
I have 700 + songs in my playlist, but when I hit shuffle he repeats the same song enlessly.
-
In previous versions of Firefox, the dev tools had on background HTML and styles on the right. Now everything is anchored at the bottom of the screen. Is it possible to extend vertically up to the full window styles? I find it hard to quickly navigat
-
On some sites that worked well, I find when I click on the button buy, I get a gray screen with the sad face. Any ideas? Thank you
-
[Sony XPERIA MINI ST15i] Camera fade after update for ICS
Hello guys, I have a problem with my XPERIA MINI. When he was on the gingerbread, the camera are superb & fine. But after the update to ICS, when go to the camera 5MP camera, its 99% fuzzy. But the 3MP is normal but not good enough. I want my back of
-
Sir (you accept my apologies for first for the writing on your Forum) lets start at the beginning, I read the reviews on the G4 motorcycle which where all very good, so being that it was my first cell phone I bought a. So at the age of 75 years I'm n