median case, conditional median
I want to get the MEDIAN of a column IF it meets the specific criteria that that are in another column. EXCEL can do so with the following formula:
MEDIAN = (IF ($A:$ A = "professional association", $B: $B))
"Because the formula itself refers to a chart, you must press CTRL + SHIFT + ENTER instead of just the ENTRY when you have finished writing the formula.
This same formula did not work in iWork Numbers.
Nor this one
= IF ($A:$ A = 'professional association', MEDIAN ($B:$B)))
I know a simple solution would be to create a new column with an IF statement, but I try to avoid that, for a number of other reasons.
When I tried to import an Excel document into Numbers, I get the error "the array formula could not be imported and was replaced by the last computed value."
TYPE |
TOTAL RECEIPTS |
Professional Association |
$1,601,466,444 |
Professional Association |
$732,697,005 |
Professional Corporation |
$601,993,361 |
Professional Corporation |
$586,676,226 |
Professional Association |
$466,733,002 |
Professional Corporation |
$462,700,048 |
Professional Association |
$457,383,677 |
Professional Association |
$389,161,833 |
Professional Association |
$311,840,739 |
Professional Association |
$276,005,771 |
The numbers do not support the so-called "table of forms" entered in Excel with ctrl-shift-enter.
You can put the table in a range of cells (in this case an additional column), with something like this:
The formula in column C is:
= IF(A="trade association",B,"")
Then take the median of this new column.
In the second table B2, I used:
= Median (Data::C)
SG
Tags: iWork
Similar Questions
-
With the help of case condition for the date of distinct values is does not
Hello PL/SQL gurus and experts.
I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
I followed two tables
TT3-
TT4create table TT3(FeesCntlr,CommCntlr,LatePayCntlr,Name,Age) as select 1,11,21,'Mike',25 from dual union all select 2,12,22,'Clark',26 from dual union all select 4,17,27,'Ussan',28 from dual union all select 5,13,21,'Linda',29 from dual union all select 6,14,24,'Obrek',35 from dual union all select 7,15,25,'Batty',45 from dual union all select 8,16,26,'Nicky',38 from dual;
Now, if I use the following DML for the year 2012, then the result is as follows-drop table TT4; create table TT4(TRNID,BlockID,FeesCntlr,CommCntlr,LatePayCntlr,BookDate) as select 221,625,1,11,21,20121101 from dual union all select 223,625,2,12,22,20121101 from dual union all select 224,625,1,11,21,20121101 from dual union all select 225,627,4,17,27,20111001 from dual union all select 226,628,5,13,21,20120701 from dual union all select 227,628,6,14,24,20120701 from dual union all select 334,628,7,15,25,20120701 from dual union all select 339,629,8,16,26,20120701 from dual union all select 393,629,1,11,21,20120701 from dual union all select 432,629,2,12,22,20120701 from dual union all select 347,629,1,11,21,20120701 from dual union all select 556,629,4,17,27,20120701 from dual union all select 558,629,5,13,21,20120701 from dual union all select 974,629,6,14,24,20120701 from dual union all select 976,629,7,15,25,20120701 from dual union all select 980,629,8,16,26,20120701 from dual union all select 1223,650,2,12,22,20110415 from dual union all select 1224,650,1,11,21,20110415 from dual union all select 1225,650,4,17,27,20110415 from dual union all select 1226,650,5,13,21,20110415 from dual union all select 1227,650,6,14,24,20110415 from dual union all select 1334,650,7,15,25,20110415 from dual union all select 1339,710,8,16,26,20120115 from dual union all select 1393,710,1,11,21,20120115 from dual union all select 1432,710,2,12,22,20120115 from dual union all select 1347,710,1,11,21,20120115 from dual union all select 1556,710,4,17,27,20120115 from dual union all select 1558,711,5,13,21,20111231 from dual union all select 1974,711,6,14,24,20111231 from dual union all select 1976,711,7,15,25,20111231 from dual ;
Now, if I use the following DML for 2011, then the result is as follows-SQL> select t3.Name,t3.age,count(t4.TRNID),count(distinct(BlockID)) from 2 tt3 t3,tt4 t4 3 WHERE t3.feescntlr = t4.feescntlr 4 AND t3.commcntlr = t4.commcntlr 5 AND t3.latepaycntlr = t4.latepaycntlr 6 AND t4.bookdate between 20120101 and 20121120 7 GROUP BY t3.name, t3.age; NAME AGE COUNT(T4.TRNID) COUNT(DISTINCT(BLOCKID)) ----- ---------- --------------- ------------------------ Mike 25 12 3 Mike 27 12 3 Batty 45 4 2 Clark 26 6 3 Linda 29 4 2 Nicky 38 6 2 Obrek 35 4 2 Ussan 28 4 2 8 rows selected.
But by using the condition if I use the following dml and results do not match-SQL> select t3.Name,t3.age,count(t4.TRNID),count(distinct(BlockID)) from 2 tt3 t3,tt4 t4 3 WHERE t3.feescntlr = t4.feescntlr 4 AND t3.commcntlr = t4.commcntlr 5 AND t3.latepaycntlr = t4.latepaycntlr 6 AND t4.bookdate between 20110101 and 20111120 7 GROUP BY t3.name, t3.age; NAME AGE COUNT(T4.TRNID) COUNT(DISTINCT(BLOCKID)) ----- ---------- --------------- ------------------------ Mike 25 2 1 Mike 27 2 1 Batty 45 2 1 Clark 26 2 1 Linda 29 2 1 Obrek 35 2 1 Ussan 28 4 2 7 rows selected.
As the expected output, that I expect - isSQL> select Name,Age,sum(Trn),sum(CurYrOrdr) "2011 Order", sum(LastYrOrdr) "2012 Order" 2 from 3 ( 4 select t3.Name,t3.age,count(t4.TRNID) Trn,(case when t4.bookdate between 20110101 and 20111231 then count (distinct(BlockID)) else 0 end) CurYrOrdr, 5 (case when t4.bookdate between 20120101 and 20121120 then count (distinct(BlockID)) else 0 end) LastYrOrdr 6 from 7 tt3 t3,tt4 t4 8 WHERE t3.feescntlr = t4.feescntlr 9 AND t3.commcntlr = t4.commcntlr 10 AND t3.latepaycntlr = t4.latepaycntlr 11 AND t4.bookdate between 20110101 and 20121120 12 GROUP BY t3.name, t3.age,t4.bookdate 13 ) 14 group by Name,Age order by Name,Age; NAME AGE SUM(TRN) 2011 Order 2012 Order ----- ---------- ---------- ---------- ---------- Batty 45 8 2 2 Clark 26 8 1 3 Linda 29 8 2 2 Mike 25 14 1 3 Mike 27 14 1 3 Nicky 38 6 0 2 Obrek 35 8 2 2 Ussan 28 8 2 2 8 rows selected.
I sincerely thank each of you in advance for the input/comments that I fight with it for some time now.---------------------------------- Expected Output - NAME AGE "2012 TRNID" "2011 TRNID" "2012 ORDERID" "2011 ORDERID" ----- ---------- --------------- ----------------------------- ---------- ------------ Mike 25 12 2 3 1 Mike 27 12 2 3 1 Batty 45 4 2 2 1 Clark 26 6 2 3 1 Linda 29 4 2 2 1 Nicky 38 6 2 2 1 Obrek 35 4 2 2 1 Ussan 28 4 4 2 2
Kindly help.user555994 wrote:
Hi JAC
Thanks for the comments and certainly once I comment out the following line.
- AND t4.bookdate between 20110101 and 20111120then the values are adapting, but at the same time why do we need to comment the date range condition as case is just a filter and not the condition.
filter should be-
AND t4.bookdate between 20110101 and 20121120 --"made it 12"
-
Hello
I have the problem.
I wrote a program that generates numbers and then write to the file.
If case condition is met the need to write value. In other cases the program needs to go to the next loop and do nothing.
What can I change in the program to solve?
Regads
Conditional tunnels to the rescue! Right-click on the exit tunnel, and then select the Tunnel Mode-> conditional.
-
Hello gurus / experts of PL/SQL,.
After execuing the request I do not receive the correct values and the cause of the problem is.
sum (CASE WHEN TO_NUMBER (SUBSTR(date,1,4)) = 2011 SO AMT END) lastYrtotal_amount,
Here's my intension to total with a case condition where year = 2011 field date. Date field is to have from YYYYMMDD format, so I extract the first four numbers and compare it to the 2011.
But the values are coming in empty.
Kindly help.. If I do something wrong?
Thank you in advance for your time and effort.user555994 wrote:
I wish that you are are very good.It is logical that the amount will be null.
It's what you doselect ... sum(CASE WHEN d.date_dim_key between 20110000 and 20119999 THEN atdf.Tag_Trd_Amt END) lastYrtotal_amount, from ... where ... AND d.date_dim_key BETWEEN 20120101 AND 20120822 ... group by d.date_dim_key ...
You see the potential problem?
Published by: Sven w. on August 24, 2012 11:42
Edited by: group by to view another question added Sven W. on August 24, 2012 11:44
-
Tag not including conditional text format AutoNumber
I try to apply a conditional text tag titles from someTable. However the AutoNumber format is not be included in the selected text. I made sure I included the carriage return when applying the Condition tag, but the AutoNumber refuses to participate.
My AutoNumber format is as follows:
Table title:-T:Table < n + >:
Oddly, when you apply the same tag to a figure of legend, the AutoNumber is included in the show/hide parameter. My auto-numbering format Figure caption is:-Figure: < $chapnum >. < n + >
So is this something to do with the way the headings of table are included in the table format indicated?
Mark
Mark,
I work in structured FrameMaker. So, I'm not sure that this explanation applies to the unstructured, but it is probably similar.
If the your table is a REAL of the table title, then it is part of the structure of the table and the table format. For example, you cannot select a table heading and just delete. You must remove it from the table designer. Even if you delete the title of the table, hide it equals delete. In other words, when you hide something that is conditioned, the part which remains on display must be a valid structure. For example, you cannot condition one cell in a table, because when he's hidden the rest of the structure is not a valid table.
Therefore, because you can not delete a table heading by simply deleting, you cannot fully condition it. In this way, when you apply the State to the title of the table, FrameMaker apply it only to the content of the title, which leaves the AutoNumber showing.
HOWEVER, some people use no actual table titles, but use a paragraph under the title with real table inserted at the end of the paragraph. In this case, conditioned to the paragraph determines the table also, because the table marker is included in the condition. So I doubt that's what you do. In your case, you probably have it set up so that the legend of the figure is a whole paragraph that does not include the brand of the anchored image that contains the chart.
To return to the tables... You want to really be able to show/hide a table title and keep the table display? If you want to show/hide the different titles, then put them all in order in the title of the table, each with the appropriate condition. In each situation, show/hide the ever-present title, but something different in each case.
If you want to do something different than the above, please specify.
Van
-
Calculate age with date of birth only? OBIEE
I would like to calculate age based on DOB. I get a syntax error. Not familiar with the proper syntax of PL/SQL for nesting of IF/THEN statements. Any help would be fantastic:
@{Current_Date} = current Date
"Employee personal attributes. "" Date of birth of the employee ' = DOB
WHEN IFNULL("Employee Personal Attributes"."Employee Birth Date", 0)<> 0 THEN WHEN MONTH("Employee Personal Attributes"."Employee Birth Date") < (Month(@{CURRENT_DATE})) Or (Month("Employee Personal Attributes"."Employee Birth Date") = Month(@{CURRENT_DATE}) And Day("Employee Personal Attributes"."Employee Birth Date") <= Day(@{CURRENT_DATE})) Then TIMESTAMPDIFF(SQL_TSI_YEAR,"Employee Personal Attributes"."Employee Birth Date", @{CURRENT_DATE}) Else TIMESTAMPDIFF(SQL_TSI_YEAR,"Employee Personal Attributes"."Employee Birth Date", @{CURRENT_DATE})-1 End ELSE 0 End
Any help would be much appreciated!
Hello
I managed to find a date column with some null on my test platform (SA406).
The formula I posted without the NULL case already return 0 when date is NULL (was not really planned).
If you want to use a CASE IFNULL WHEN ("personal attributes used". "" Employee Date of birth»(, 0) <> 0 THEN you'll get an error: "
[nQSError: 59021] CASE conditional expressions have correspond to data types.
So 2 options:
CASE WHEN IFNULL ("personal attributes used". "" Date of birth of the employee»(, CURRENT_DATE) <> CURRENT_DATE THEN "
TIMESTAMPDIFF (SQL_TSI_YEAR, "personal attributes used" "." ") Date of birth of the employee", CURRENT_DATE) + BOX WHEN DAYOFYEAR ("personal attributes used". "Date of birth of the employee") > DAYOFYEAR (CURRENT_DATE) - THEN 1 ELSE 0 END "
ELSE 0 END
or
TIMESTAMPDIFF (SQL_TSI_YEAR, IFNULL ("personal attributes used". "" Date of birth of the employee "(, CURRENT_DATE)(, CURRENT_DATE) + BOX WHEN DAYOFYEAR (IFNULL ("personal attributes used"." Date of birth of the employee", CURRENT_DATE)) > DAYOFYEAR (CURRENT_DATE) - THEN 1 ELSE 0 END
Both did the same thing.
-
Hello
I have 2 ID prompt and BIC
Once I set variable presentation. I spent this values in my report filter. In the report filter, I put "Covert this filter SQL" option.
But when I choose values in my two guest so I can able to see the values in my report. But when I choose only guest the value then not able to display.
Please check my filter. When I put directly as Credit_Bic ' %' then works fine but when I put a case condition then not show all records?
and "Case header '." ID credit"LIKE (BOX WHEN '3582020570001' =" THEN ' %% 'ELSE END ' 3582020570001') and "Case header '." Bic credit"LIKE (BOX WHEN"="THEN ' %' OTHER ' @{ClientBIC}' END) Thank you
Gram
Solved.
and "Case header '." Credit Id' AS (CASE THAT '3582020570001' IS NULL THEN ' %% 'ELSE END ' 3582020570001') and "Case header '." Bic credit"AS (BOX WHEN" IS NULL THEN ' %' OTHER ' @{ClientBIC}' END)
I put IS NULL instead of =
-
IFNULL OBIEE 11.1.1.5
I am trying to replace a column null 'n/a', and I know it's a different data format, but it's what the customer is asking.
That's what I use: IFNULL ("COLUMN," n/a ")
That's what I have: State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000]
[nQSError: 10058] A general error occurred. [nQSError: 43113] Message
returned by OBIS. [nQSError: 43119] Query Failed: [nQSError: 59021] CASE
conditional expressions have correspond to data types. (HY000)If I use a '0' instead of n/d, it works. Is there a way to get around this?
He mistakes in the RPD as well when I use it.
Hello
try to cast() column in the required format. If it's number and you want to use "S/o" then try to use cast (COLUMN as CHAR).
something like: ifnull (cast (char type COLUMN), "N/a"). I hope it should work.
Kind regards
KN
-
Run one or the other query based on the result
Hi all
Is there anyway that I can design this query to run only a subquery based on the returned results.
Thank youselect to_char((NEXT_CHANGE# - 1),9999999999999999) latest_change from v$archived_log where SEQUENCE# =(select nvl(min(SEQUENCE#),0) from v$archived_log where ARCHIVED='YES' and APPLIED='NO') If the above subquery returns 0, then I would like to execute the query below. Is there any way to embed multiple queries like case conditions ? select max(SEQUENCE#) from v$archived_log where ARCHIVED='YES' and APPLIED='YES'
G
Edited by: USER101 December 9, 2010 09:34Hello
Use the operator to decode your subquery:Select to_char ((NEXT_CHANGE #-1), 9999999999999999) latest_change
v $ archived_log
where SEQUENCE # = decode ((select nvl (min(SEQUENCE#), 0)))
v $ archived_log
When ARCHIVED = 'YES '.
and APPLIED = 'NO'),
0,
(select max(SEQUENCE#)
v $ archived_log
When ARCHIVED = 'YES '.
and APPLIED = 'YES'),
(select nvl (min(SEQUENCE#), 0))
v $ archived_log
When ARCHIVED = 'YES '.
and APPLIED = 'NO')); -
Dynamic expression in interface
Hi all
Could someone share a way how to create the dynamic expression in ODI interface. For example. I metadata and want to build an expression box on its base and use it in the interface.
I tried several possibilities:
(1) Java use in expression mapping program.
But during the stages of the interface creation getJDBCConnection() method returns NULL for SRC and DEST.
It is a way to connect to the database?
(2) generate the expression in the procedure and use it in the interface
Is there a way how to pass the string interface procedure?
(3) use variable to generate the expression
Pure SQL is not enough to generate my expression, I need to cycles, ifs etc.
(4) use special IKM that replace some symbols of substitution with generated expression.
Well, if there is no other choice I'll pick this up but don't want to have extra KM special.
Could someone suggest another solution or workaround for referred?
Thanks in advance!
Oleg IvanovHere is the solution
Step 1. Java ODI procedure
Create a new procedure in the
Command on Source - technology - Oracle, and schema-Target - technologies - Java Bean shell command and paste the following code
<@ import java.sql.Connection; import java.sql.Statement; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; conn=odiRef.getJDBCConnection("SRC"); Statement stmt=conn.createStatement(); String result="CASE "; char delimiter=(char)13; my_query= "select 'WHEN '||SRC_TAB_COLUMN||' = '||SRC_TAB_COLUMN_VALUE||' THEN '''||PRODUCT_NAME||'''' AS OUTPUT FROM ODI_TEMP.metadata"; ResultSet rs=stmt.executeQuery(my_query); while (rs.next()) { String output=rs.getString("OUTPUT")+ delimiter; result+=output; } result+="END"; stmt.close(); conn.close(); @>
[Note: Please change the name of the Table, column, as required]
In the interface where you want to call the condition had the following code<@=result@>
and set it to put in domain.
I tested the java code and I get after sample case conditionCASE WHEN Call_Type = 10 THEN 'SMS' WHEN Call_Type = 20 THEN 'MMS' WHEN Call_Area = -1 THEN 'Unknown' END
In the package call first ODI then Interface procedure and run as a set only.
Hope this fixes your requirement for dynamic business condition. -
Model Menu XML and security of ADF
I use:
JDeveloper R1 (11.1.1.1.0)
ADF configured security and work
Menu ADF model to generate the navigation level 1 and 2 items in the page template
Use case:
Conditionally render nodes item in my Menu ADF using el specifically, I need to render that element nodes that the user is allowed to view the role of ADF Security Application.
Comments:
To test this point, I put the property made to an itemNode # {securityContext.authenticated}. Note: The user is not authenticated.
If I statically set this value to false, the tab is not rendered as expected, however using the securityContext in this case doesn't seem to work. The EL expression returns 'false', since I added it in the form of text on the page outputText component.<itemNode id="itemNode_Search" label="Search" action="adfMenu_Search" focusViewId="/Search" rendered="#{securityContext.authenticated}" immediate="true"/>
If this work or securityContext is available because the adfc - config.xml is not covered by the safety of the ADF?
What is the best way to accomplish this behavior?
Thank you
Published by: rvlong on April 20, 2010 15:31I had the same problem on one of my projects.
Make sure that you have added rendered = "#{menuInfo.rendered}" for the elements of your model. "
I had a few problems using EL in the rendered itemnode attribute, but after that I updated my model as above it worked fine.
-
Impossible to get Min, Max and median of the values in the date range values
Hello
I had a requirement as to show the data of each charge group of wise men as '< 100' ' 100-199 "" 200-299 "" 300-399 "400-499, 500-599 600-699 700-799 800-899 900-999 > = 1000 '"»
With the query be able to get the count between the beach and the total below. But impossible to get the Min and Max values for this range. For example if the County < 100 is 3 then in these 3, the lowest value is need to display in the min. Idem for Max column also.
In the light of the median value on these values.
Thanks in advance.
Requirement is as below:
State < 100 100-199, 200-299 300-399 400-499, 500-599 600-699 700-799 800-899 900-999 > = 1000 Min Total median Max
AK 1 2 0 4 1 4 4 35 35 4 1 $25 $85 850 $1,200
AL 0 0 2 27 10 17 35 2 2 35 0 $103 100-$1 500 750
* "QUERY ' * '"
WITH t AS
(SELECT 'AL' State, 12 DUAL FROM VALUE
UNION ALL
SELECT 'AL' State, 67 FROM DUAL VALUE
UNION ALL
SELECT 'AL' State, 23 FROM DUAL VALUE
UNION ALL
SELECT 'AL' State, 12 DUAL FROM VALUE
UNION ALL
SELECT 'AL' State, 12 DUAL FROM VALUE
UNION ALL
SELECT 'AL' State, 78 FROM DUAL VALUE
UNION ALL
SELECT 'AL' State, 34 FROM DUAL VALUE
UNION ALL
SELECT 'AL' State, 4 DUAL FROM VALUE
UNION ALL
SELECT 'AL' State, 12 DUAL FROM VALUE
UNION ALL
SELECT 'AL' State, 15 VALUE FROM DUAL
UNION ALL
SELECT "AZ" State, FROM DUAL VALUE 6
UNION ALL
SELECT "AZ" State, 123 FROM DUAL VALUE
UNION ALL
SELECT "AZ" State, 123 FROM DUAL VALUE
UNION ALL
SELECT 'MY' State, 23 FROM DUAL VALUE
UNION ALL
SELECT 'MY' State, 120 FROM DUAL VALUE
UNION ALL
SELECT 'MY' State, 456 FROM DUAL VALUE
UNION ALL
SELECT 'MY' State, 11 FROM DUAL VALUE
UNION ALL
SELECT 'MY' State, 24 FROM DUAL VALUE
UNION ALL
SELECT 'MY' State, 34 FROM DUAL VALUE
UNION ALL
SELECT 'MY' State, 87 DUAL FROM VALUE
UNION ALL
SELECT 'MY' State, 23 FROM DUAL VALUE
UNION ALL
SELECT 'MY' State, 234 DUAL FROM VALUE
UNION ALL
SELECT 'MY' State, 789 FROM DUAL VALUE
UNION ALL
SELECT "HD" State, VALUE FROM DUAL 54321).
-End of test data
AS T1
(SELECT State,
NVL (COUNT (DECODE (VALUE, 0, 0)), 0) '< 100 ',.
NVL (COUNT (DECODE (VALUE, 1, 1)), 0) '100-199.
NVL (COUNT (DECODE (VALUE, 2, 2)), 0) '200-299.
NVL (COUNT (DECODE (VALUE, 3, 3)), 0) '300-399.
NVL (COUNT (DECODE (VALUE, 4, 4)), 0) '400-499.
NVL (COUNT (DECODE (VALUE, 5, 5)), 0) '500-599,'
NVL (COUNT (DECODE (VALUE, 6, 6)), 0) '600-699.
NVL (COUNT (DECODE (VALUE, 7, 7)), 0) '700-799.
NVL (COUNT (DECODE (VALUE, 8, 8)), 0) '800-899.
NVL (COUNT (DECODE (VALUE, 9, 9)), 0) '900-999. "
NVL (COUNT (DECODE (VALUE, 10, 10)), 0) ' > = 1000.
(SELECT STATE,
CASE
WHAT VALUE < 100 THEN 0
WHAT A VALUE BETWEEN 100 AND 199 THEN 1
WHAT VALUE BETWEEN 200 AND 299, THEN 2
WHAT VALUE BETWEEN 300 AND 399 THEN 3
WHAT VALUE BETWEEN 400 AND 499 THEN 4
WHAT VALUE BETWEEN 500 AND 599 5 THEN
WHAT VALUE BETWEEN 600 AND 699 6 THEN
WHAT VALUE BETWEEN 700 AND 799 THEN 7
WHAT VALUE BETWEEN 800 AND 899 8 THEN
WHAT VALUE FROM 900 TO 999 9 THEN
WHAT VALUE > = 10 THEN 1000
END
VALUE
T)
GROUP BY State)
SELECTION STATE,
"< 100."
"100-199.
"200 299",
"300-399.
"400-499.
'500-599,'
"600-699.
"700-799.
"800-899.
"900-999."
"> = 1000."
'< 100 '.
+ "100-199.
+ "200-299.
+ '300-399.
+ '400-499.
+ "500-599.
+ '600-699.
+ "700-799.
+ "800-899.
+ '900-999 ".
+ ' > = 1000.
in total,.
less ("< 100",)
"100-199.
"200 299",
"300-399.
"400-499.
'500-599,'
"600-699.
"700-799.
"800-899.
"900-999."
("> = 1000 ') min_val,.
largest ("< 100",)
"100-199.
"200 299",
"300-399.
"400-499.
'500-599,'
"600-699.
"700-799.
"800-899.
"900-999."
("> = 1000 ') max_val
FROM t1
/Why not keep it simple?
WITH t AS (SELECT 'AL' state, 12 VALUE FROM DUAL UNION ALL SELECT 'AL' state, 67 VALUE FROM DUAL UNION ALL SELECT 'AL' state, 23 VALUE FROM DUAL UNION ALL SELECT 'AL' state, 12 VALUE FROM DUAL UNION ALL SELECT 'AL' state, 12 VALUE FROM DUAL UNION ALL SELECT 'AL' state, 78 VALUE FROM DUAL UNION ALL SELECT 'AL' state, 34 VALUE FROM DUAL UNION ALL SELECT 'AL' state, 4 VALUE FROM DUAL UNION ALL SELECT 'AL' state, 12 VALUE FROM DUAL UNION ALL SELECT 'AL' state, 15 VALUE FROM DUAL UNION ALL SELECT 'AZ' state, 6 VALUE FROM DUAL UNION ALL SELECT 'AZ' state, 123 VALUE FROM DUAL UNION ALL SELECT 'AZ' state, 123 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 23 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 120 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 456 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 11 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 24 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 34 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 87 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 23 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 234 VALUE FROM DUAL UNION ALL SELECT 'MA' state, 789 VALUE FROM DUAL UNION ALL SELECT 'MH' state, 54321 VALUE FROM DUAL) SELECT state , NVL( COUNT( case when VALUE < 100 then 0 end ), 0 ) "<100" , NVL( COUNT( case when VALUE between 100 and 199 then 0 end ), 0 ) "100-199" , NVL( COUNT( case when VALUE between 200 and 299 then 0 end ), 0 ) "200-299" , NVL( COUNT( case when VALUE between 300 and 399 then 0 end ), 0 ) "300-399" , NVL( COUNT( case when VALUE between 400 and 499 then 0 end ), 0 ) "400-499" , NVL( COUNT( case when VALUE between 500 and 599 then 0 end ), 0 ) "500-599" , NVL( COUNT( case when VALUE between 600 and 699 then 0 end ), 0 ) "600-699" , NVL( COUNT( case when VALUE between 700 and 799 then 0 end ), 0 ) "700-799" , NVL( COUNT( case when VALUE between 800 and 899 then 0 end ), 0 ) "800-899" , NVL( COUNT( case when VALUE between 900 and 999 then 0 end ), 0 ) "900-999" , NVL( COUNT( case when VALUE >= 1000 then 0 end ), 0 ) ">=100" , count( value ) "total" , min( VALUE ) "min" , max( VALUE ) "max" , avg( VALUE ) "avg" , median( value ) "median" from t group by state
-
Hello
I need to get the MEDIAN for the last 10 dlvry_wk as well as for the last 4 - but I need this in a pivot format. I know how to make a pivot, but I do not know how to add the median for the pivot.
The example data:
The pivot query I have is:CREATE TABLE ORDERS ( FRUIT VARCHAR2(25), DLVRY_WK NUMBER(6), ORDERS NUMBER(5)); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201235,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201231,1); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201232,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201237,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201238,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201242,5); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201234,1); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201236,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201241,3); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201243,3); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('PEACHES',201239,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('GRAPES',201232,1); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('GRAPES',201240,1); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('GRAPES',201237,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('GRAPES',201241,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('ORANGES',201240,4); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('ORANGES',201238,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('ORANGES',201239,1); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('ORANGES',201232,3); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('ORANGES',201231,1); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('ORANGES',201237,1); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('ORANGES',201235,1); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('ORANGES',201234,4); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('ORANGES',201242,3); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201236,7); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201240,4); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201241,11); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201237,2); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201234,6); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201232,7); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201238,1); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201243,3); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201239,4); INSERT INTO ORDERS (FRUIT,DLVRY_WK, ORDERS) VALUES ('APPLES',201242,4);
And I want the results to look like this - where m10 is the median for the past 10 weeks and m4 is the median for the last 4:select fruit , NVL(wk34_atc,0) as wk34_atc , NVL(wk35_atc,0) as wk35_atc , NVL(wk36_atc,0) as wk36_atc , NVL(wk37_atc,0) as wk37_atc , NVL(wk38_atc,0) as wk38_atc , NVL(wk39_atc,0) as wk39_atc , NVL(wk40_atc,0) as wk40_atc , NVL(wk41_atc,0) as wk41_atc , NVL(wk42_atc,0) as wk42_atc , NVL(wk43_atc,0) as wk43_atc from orders pivot (max(orders) as atc for dlvry_wk in ( '201234' as wk34 , '201235' as wk35 , '201236' as wk36 , '201237' as wk37 , '201238' as wk38 , '201239' as wk39 , '201240' as wk40 , '201241' as wk41 , '201242' as wk42 , '201243' as wk43));
34 34 35 36 37 38 39 40 41 42 43 m10 m4 ORANGES 4 1 0 1 2 1 4 0 3 0 1 1.5 PEACHES 1 2 2 2 2 2 0 3 5 3 2 3 GRAPES 0 0 0 2 0 0 1 2 0 0 0 0.5 APPLES 6 0 7 2 1 4 4 11 4 3 4 4
How you calculate the median, you change nulls to 0 before making the median. This means that you need to "densify" the data.
with dense_data as ( select fruit, dlvry_wk, row_number() over(partition by fruit order by dlvry_wk desc) rn from (select distinct fruit from orders), (select distinct DLVRY_WK from orders) ), all_data as ( select fruit, dlvry_wk, nvl(orders, 0) orders, median(case when rn <= 4 then nvl(orders, 0) end) over(partition by fruit) last_4, median(case when rn <= 10 then nvl(orders, 0) end) over(partition by fruit) last_10 from dense_data left join orders using(fruit, dlvry_wk) ) select * from all_data pivot (max(orders) as atc for dlvry_wk in ( '201234' as wk34 , '201235' as wk35 , '201236' as wk36 , '201237' as wk37 , '201238' as wk38 , '201239' as wk39 , '201240' as wk40 , '201241' as wk41 , '201242' as wk42 , '201243' as wk43)); FRUIT LAST_4 LAST_10 WK34_ATC WK35_ATC WK36_ATC WK37_ATC WK38_ATC WK39_ATC WK40_ATC WK41_ATC WK42_ATC WK43_ATC -------- ------ ------- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- APPLES 4 4 6 0 7 2 1 4 4 11 4 3 ORANGES 1.5 1 4 1 0 1 2 1 4 0 3 0 PEACHES 3 2 1 2 2 2 2 2 0 3 5 3 GRAPES 0.5 0 0 0 0 2 0 0 1 2 0 0
-
Find the median of a set of data
I have a table that looks like this:
Range
Set of data: range values
Data set b: range values
0.00 - 0.99
35
67
1.00 - 1.99
35
40
2.00 - 2.99
49
54
3.00 - 3.99
41
45
4.00 - 4.99
36
38
5.00 - 5.99
31
34
6.00 - 6.99
22
29
7.00 - 7.99
30
20
8.00 - 8.99
24
16
9.00 - 9.99
16
11
10.00 - 10.99
15
10
11.00 - 11.99
12
5
12.00 - 12.99
11
1
13.00 - 13.99
5
2
14.00 - 14.99
5
1
15.00 - 15.99
2
0
16.00 - 16.99
1
0
17.00 - 17.99
2
0
18.00 - 18.99
1
0
How can I find the median interval for each set of data (A and B)?
Thanks for your help!
Median and range are two different things from what I remember. Can you please send a link to a Web site that could describe what a "median line"?
Median is the average of a set of data (even counting data sets usually take the average < average > the values of two intermediate points)
Range is simply the max - min.
Jason
-
Build table 2D-the only condition of case string
Hello
I'm having a problem when I am trying to build a 2D of the elements of the string table. Here's basically what I'm doing:
I'm loading the tables in different text files (Session_001.txt, Session_002.txt, etc.) and concatenate into 1 big table.
On each line of text Session files, there is the session number, various characteristics of hockey sticks, and then a couple results.
I want to be able to select the various features and then display the corresponding results. Currently, I'm working on the selection of the Session, and when I get this working, the rest would be similar (I guess).
The problem I have is that when I select the sessions that I want, the Array3 resulting (with all data) is filled with empty lines (table 1 d of the empty elements). I had the same problem when display a table 1 d (table 2) coming to show what Sessions had been selected, but I managed to fix that by searching for and deleting empty elements.
The problem lies within the structure of matter I. I compare all the elements in the first column of my huge 2D array with each number of the selected Session, and when it is 'true', that I keep the current line to go to table 3. If it is "false", nothing should happen (I have a registry change through my case 'false', but a line of empty strings is added to the table.
What Miss me?
I know this probably sounds very confusing, so I join you the only VI and a zip containing the VI and my text files.
Thank you!
Off topic (Finally, still on the topic of my VI), it will be possible to assign a different color for each type of stick (MX3, APX3) or the different type of marker for different types of shots (WS, SS), etc., when I want to display the results on the same graph? If not, stop now and I'm going to Matlab.
Oh my... Equal to true. I'm so ashamed.
I just started Labview on my internship 2 weeks ago. There are probably several simplifications I can do for my screws, but as long as they work and do not burn my laptop, I agree.
With respect to the conditional tunnel, I n, t really know to use it yet, but I found the problem with my registry to offset. I created a 2D array empty outside the two loops and added a registry to offset. I then build I tried to rely on another thread.
Resolved VI is attached to anyone who cares
Maybe you are looking for
-
waether app not working not
-
Cannot start linux USB drive on the PC of Compaq CQ2903ES
Hello I am trying to install linux on a Compaq CQ2903ES desktop PC. I disabled startup secure on the bios, but the system does not boot from a linux live USB. Any suggestions? Thanks in advance.
-
Apple Watch and AT &; T Sync number
I have AT & T number Sync works fine on some Mac and iPad, coordinated by my iPhone. All works well - I can even put the phone in airplane mode or turn it completely off and continue to use the Mac and iPad to call and send SMS. I can also use the Ap
-
Multi device Synch AO series via RTSI
I have two analog output AO Series devices connected via the RTSI. I've defined the RTSI cable in MAX and added the two planks. I have trouble getting the slave to use the sample clock master. According to "Timing and synchronization features of NOR-
-
How can I restore my PC to last time?
I downloaded a new vertion of the emusic handler and now everything is locked up. I'm afaid if I have an install emusic manager all together it can destroy my music. I wanted to restore my HP Pavilion Slimline s5220f running windows 7 to a permeable