Will RANK get confused if you have not ORDERed the data?
Will the resulting ranking column contain garbage or would it just return #ERROR ?
No, it will return a valid value (the ordinal position of the specified tuple in the set)
Rank (MDX)
http://msdn.microsoft.com/en-us/library/ms144726.aspx
It appears that this was only the case for 2000 (so says Wiley's "MDX Solutions")
Related
ANSWER: Need to use LEAD and PARTITION BY functions. Please refer to Gordon's answer.
I have the following dataset :
I want to get rows 1,3,5,7 in the result set.
RESULT SET SHOULD LOOK LIKE :
11/10/2020 19:36:11.548955 IN_REVIEW
11/8/2020 19:36:11.548955 EXPIRED
11/6/2020 19:36:11.548955 IN_REVIEW
11/4/2020 19:36:11.548955 ACTIVE
Use window functions. LEAD() gets the value from the "next" row, so filter only when the value changes:
SELECT t.*
FROM (SELECT t.*,
LEAD(interac_Reg_stat) OVER (PARTITION BY Acct_No ORDER BY xcn_tmstmp) as next_interac_Reg_stat
FROM TABLE
) t
WHERE interac_Reg_stat <> next_interac_Reg_stat OR
next_interac_Reg_stat IS NULL;
Well, since you are grouping by interac_Reg_stat, you will never get 2 separate rows for the IN_REVIEW status. To get the result you want, you will need to add a sub-query to find all items with a certain interac_Reg_stat that are before another specific interac_Reg_stat.
I am trying to figure out how can I use dimension values as one of the set modifiers in Expressions in qlikview. Consider the following:
Raw Data:
PName, count
AB,2
BC,3
CD,4
Dimension:
Name
Expression:
SUM(<{PName=Name}>count)
i-e using the dimension value as one of the set modifiers.
Thanks
As #bdiamante said. It is not clear what you exactly want to do.
But I assume that you only want to use the current value of the dimension to calculate the count of names.
If that is true, then you can simply say:
Expression:
=sum(count)
HTH
I believe I understand. Try sum({<Pname=p(Name)>}count). This says that pname will be the possible values of name. Also look into e() which is the excluded values.
If Name is a literal value, try this:
sum({<PName={'AB'}>}count)
It would always give you the count as if someone had selected PName = 'AB'.
If you only want it to show the count for AB, if AB has not been excluded based on the current selections (e.g. someone has selected PName of 'BC'), then use:
sum({<PName*={'AB'}>}count)
This will give you the count for AB, but only if AB is included in scope for (i.e. intersects with) the current selections.
What is the logic behind MIN() aggregate function to evaluate data-types like 'CHAR' or 'VARCHAR2' ?
Min( VarcharType ) will return the lowest string value for that column in the result set, given the sorting order of the column in question.
Also MIN() returns the shortest string (in terms of length) but it's alphabetically ordered.
eg- There are two fruits :
1. Apple,
2. Kiwi.
Output:
Apple (because A comes before K although Kiwi is shorter than Apple).
Assume I have a table with a column of integers in Oracle. There are a good amount of rows; somewhere in the millions. I want to write a query that gives me back an integer that is larger than 80% of all of the numbers in table. What is the best way to approach this?
If it matters, this is Oracle 10g r1.
Sounds like you want to use the PERCENTILE_DISC function if you want an actual value from the set, or PERCENTILE_CONT if you want an interpolated value for a particular percentile, say 80%:
SELECT PERCENTILE_DISC(0.8)
WITHIN GROUP(ORDER BY integer_col ASC)
FROM some_table
EDIT
If you use PERCENTILE_DISC, it will return an actual value from the dataset, so if you wanted a larger value, you'd want to increment that by 1 (for an integer column).
I think you could use the NTILE function to divide the input into 5 buckets, then select the MIN(Column) from the top bucket.
When updating a row, I want to have a built-in check to do some bounds checking. Most languages have a MAX() function to return the maximum of the arguments passed, but MySQL seems to use MAX() for something else. For example:
UPDATE person SET dollars = MAX(0, dollars-20) WHERE id=1
I want to subtract 20 dollars from person id 1, but I don't want dollars to ever be represented by a negative value, so I want a built-in comparison with 0. Does this work? Or is there another way? Thanks!
MySQL supports a function called GREATEST(). It returns the largest value among a list of its arguments.
UPDATE person SET dollars = GREATEST(0, dollars-20) WHERE id=1
This isn't a standard function in ANSI SQL, so don't count on it being available in other brands of SQL database. If you need a vendor-independent solution, use the CASE syntax suggested by others. But if all you need to use is MySQL, this function is more concise.