Cassandra: converting integer to decimal value using cast function error - cassandra

I am trying to get the average of a column and I want the output to be in decimal format. The column in question is called rating_place and it is of type int.
Sample data in column rating_place is 5, 1, 6, 2, 6, 6, 3, 8, 9, 4 .
This is my code:
CREATE INDEX ON place_ratings (place_name);
SELECT CAST(avg(rating_place) AS float) FROM place_ratings WHERE place_name = 'Taco Bills';
When I run this code it returns the value 8, but it should be 8.25. What changes do I need to make to my code to get the output in decimal form and not integer form?
Thanks.

Related

Excel: Extracting numbers from a string with variable length

I have a column with data that looks like this:
Day
D003
D004
D008
D010
D012
D028
And in the next column, I need to extract just the 3, 4, 10, 12, etc. with NO leading 0's. I tried the following:
=IF(D8="D003 Predose","30",IF(D8="D003 End","31",IF(D8="D003 4hours","34",RIGHT(D8,LEN(D8)-FIND(RIGHT(SUBSTITUTE(D8,"0",""),1),D8)+1))))
Which works for the 4, 5, 8. But for the 12, 17, 21, etc it only gives me the last number. How do I account for the variable length of those strings? I'm really new at Excel and creating formulas "from scratch" so I apologize if the answer is right in front of my nose. If there's a cleaner way to do this, I'm also all ears.

Is there an Excel Formula which returns at WHAT POINT in an active string of data, data changes form (from 1 to 2)?

Folks, REALLY would appreciate help <3
If I have the following strings of data in Excel (3 examples below) where data is coded as 1 or 2, does anyone know an Excel formula which can tell me WHEN in the sequence the data switches from 1 to 2? i.e., in the example, at the 4th, 2nd, and 8th point/column along, out of the 9.
1, 1, 1, 2, 2, 2, 2, 2, 2.
1, 2, 2, 2, 2, 2, 2, 2, 2.
1, 1, 1, 1, 1, 1, 1, 2, 2.
So far, I am able to use the following formula (see below) to see IF there is a change from 1 to 2 in the sequence, but now need to know WHEN the change occurs.
=IF(ISERROR(FIND("21",TEXTJOIN("",TRUE,[data range of a row]))),FALSE,TRUE)
The Find() function actually return the position of the target string.
Instead of IF(ISERROR(..., use
=iferror(FIND("21",TEXTJOIN("",TRUE,[data range of a row])),FALSE)
and better link the previous post for system integrity purpose.
You just need to find the number '2' by using:
=ROUNDUP(FIND(2,A1)/3,0)

Interview question about "largest range" makes no sense

Here's the question. I'm actually dumbfounded. I don't even get the question. What are they on about?
What even is a largest range? What do they mean by largest? What's a range? They say a range is a collection of numbers that come right after each other in the set of real integers. Okay, so 1, 2, 3, 4, stuff like that, right? But then they say the numbers need not be ordered or even adjacent.... but then they're not coming right after each other!! They are contradicting their own previous statement. Now I have no idea what a range is.
Their example doesn't help either. Why is [0, 15, 5, 2, 4, 10, 7] the largest range in that vector?
What is going on?
It's not very clear in the question, but I'm pretty sure the interviewer means a "range" is a set of consecutive numbers (n, n+1).
The range [0,7] is actually [0,1,2,3,4,5,6,7] since all of those appear in the full set.
The actual order doesn't matter.
In the example you were given in the interview, which you list in your question as well, the input array is: [1, 11, 3, 0, 15, 5, 2, 4, 10, 7, 12, 6]. The reason that the "largest range" is identified as [0, 7] is because all the numbers between 0 and 7 are included in that array.
There isn't another range in the input array that has a longer range than 0 to 7. For instance, there is a [10, 12] range in the input array, but that array has a length of 3 that is smaller than the length of [0, 7] range, which is 8.
In this case, the range is understood as a continuous list of integers, the largest range is the list with the most number of integers.
It means
Find the largest continuous range of numbers
For eg. in array [0,1,2,5,6,7,8,9,10]
There are 2 continuous list
[0,1,2] and [5,6,7,8,9,10] but as the larger range is the second one. so the output must be [5,10].
i.e. The largest and smallest of the largest range.

Using result of an Excel array function in a calculation

I am attempting to count instances of a particular value in Excel, from the last instance of a prior value.
Assume a vertical list starting in cell A1: 1, 2, 3, 4, 5, 4, 5, 3, 4, 5, 2, 3, 4, 3, 4, 2, 3, 4, 5
I can use an array function in, say B14 (A14 value: 3), of {=MAX(ROW($1:14)*(A$1:A14=A14-1)) to give me the row number of the last instance of a "2" (row 10).
I can then have, in C15, a function =COUNTIF(OFFSET(A14,0,0,B14-ROW(A14),1):A14,A14), which will count the instances of 3's since the last 2.
The question is: how do I integrate that array function directly into the final formula, so as not to have to waste a column with the interim calculation?
Edit
The list of numbers represents a level of indentation, so the end result will be a compound of these calculations with different offset checking to provide section numbering: 1; 1.1; 1.1.1, 1.2, 1.2.1, 1.2.2, etc
I want a single function that can calculate this entire depth level, without having to waste several columns identifying how many rows above the previous indent layer was defined.
Try in cell B14 this formula array:
{=COUNTIF(OFFSET($A14,0,0,
MAX(ROW($1:14)*($A$1:$A14=$A14-1))
-ROW($A14),1):$A14,$A14)}

Formula logic for extracting specific cell data

For extracting First £ figure and not the second one from sample data
(24M UNLTD+INS 30GB £347+£30 S6)
Following array formula has been used in Stackoverflow questions.
{=MID(A1,FIND("£",A1),MIN(IF(ISERROR(MID(MID(A1,FIND("£",A1)+1,999),ROW($1:$999),1)+0),ROW($1:$999),999)))}
I attempted an analysis of the formula as represented in the image below. I am not able to grasp the logic of part
MIN(IF(ISERROR(MID(MID(A1,FIND("£",A1)+1,999),ROW($1:$999),1)+0),ROW($1:$999),999))
As to how it leads to a figure of 4. Request that this part of formula be elaborated to clarify the role of various constituents of this formula.
Try the following as a standard (non-array) formula,
=--REPLACE(REPLACE(A2, 1, FIND("£", A2), ""), FIND("+", REPLACE(A2, 1, FIND("£", A2), "")), LEN(A2), "")
First the inside REPLACE(A2, 1, FIND("£", A2), "") erases everything up to the first £ symbol, then the same logic is applied to erase everything in that modified text from the first + to the end. The -- converts text-that-looks-like-a-number to an actual number.
The array formula you provided uses a more convoluted logic.
FIND("£", A2) + 1 finds the starting point of the first number after the first £ symbol. e.g. The first £ is the 20th character so it returns 21.
MID(A2, FIND("£",A2)+1, 999) extracts the text following that first £ symbol. The text might look like it starts with a number but it is text masquerading as a number. e.g. 347+£30 S6
In an array formula, ROW($1:$999) processes as a sequence of numbers from 1 to 999, incrementing by 1 for each cycle of calculation.
MID(MID(A1, FIND("£", A1) + 1, 999), ROW($1:$999), 1) + 0) returns an array of text values, each one 1 character long and 1 position deeper into the text than the previous one. e.g. 3, 4, 7, +, £, etc.
+0 is used to try and convert each of these pieces of text to a number. The IFERROR function returns TRUE if a piece of text cannot be converted to a true number. The first one that cannot be turned into a true number is the 4th e.g. +
The IF catches the TRUE on the fourth position and returns 4 from the second ROW($1:$999). It has returned 999 for positions 1, 2 and 3. e.g. 999, 999, 999, 4, 5, etc.
The MIN catches the smallest of these numbers returned as an array. This is where the 4 comes from. e.g. 999, 999, 999, 4, 5, 999, ...
You can see this yourself by changing all of the 999's to 9 then using the Evaluate Formula command. The reason changing to 9 is important is so that the returned arrays of number look like 1, 2, 3, 4, 5, 6, 7, 8, 9 which does not obfuscate the results quite a badly as 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... 998, 999.
        This shows the formula evaluated several steps into the process. Note the 4 being returned to the MIN function.

Resources