how to sort 2 different columns in google sheet individually? - sorting

I have a Google Sheet that has 2 columns with integer rows in it. Both these columns have no relation to each other. But when I apply a A->Z sort on the 1st column the 2nd column values also change and vice versa. My task is to SORT these 2 columns individually in ascending order and create a 3rd column which checks if the values of this 1st 2 column are equal or not.
Example:
Col1 Col2
4 5
1 8
2 9
5 1
Expected Output after sorting them individually:
col1 col2
1 1
2 5
4 8
5 9

Solution 1:
You can filter and sort each column separately:
Solution 2:
Another solution would be to create the desired output by sorting each column separately and concatenating the results:
={{"Col1";sort(A2:A)},{"Col2";sort(B2:B)}}

Related

How to remove duplicates based on column value

I need to pick a row based on a column value, example:
COLUMNID COLUMN2 COLUMN3 COLUMN4 PRIORITY
1 value34 null S 2
1 value34 5 N 1
2 value23 5 S 2
I need to load the row with the priority 1.
My distinct is based on all columns but priority.
I can not use SQL override
Use Aggregator and group by all the columns except PRIORITY, add new output port to calculate MIN(PRIORITY). Done.

Complex count row etl requirement

I have a requirement related as below
1-If there is employee record then count the number of rows
a-if there are four rows then follow the layout 1,
and populate the column1 and column 2 with values in report and ltrimrtrim
b- if there are three rows, then follow the layout 2,
and hardcode the column 1 and column 2 with NULL
Otherwise, look for the employee record.
Couldn't get the logic, I used the router with as if column 1 and two null the send to layout two else 1. But the requirement is different.
router transformation, if null, layout one else 2
Step 1 - Use SRT>AGG>JNR to calculate count. create new column as count_all and set to COUNT(*). Please group by proper key columns.
Step 2 - Use RTR next to split data based on your condition.
group 1- count_all =4 then follow the layout 1 and...
group 2- count_all =3 then follow the layout 2 and...
group 3 - if count <3 then do employee record.

OBIEE case statement check on non excistence

I have the following situation:
column 1 column 2 column 3
A 1 1
A 1 2
B 3 4
B 3 5
I need to color my letters when the value in column 2 never occurs in column 3. But I need to color all my letters. Does anyone know how to write a case statement for this?
So I'll explain my example: I dont't need to color the letter A because there is a match between column 2 and 3 and the first row.
I do need to color my B's because there is never a match between columns 2 and 3.
I already tried this:
count(distinct(case when "Column 2" != "Column 3" then 1 else 0 end))
but this gives a result for each row and I need a result for the total package.
Thanks!
You can approach this as following:
Create a logical column on your analysis that does a case statement that returns 1 or 0 depending if the values of column2 and column3 are the same (pretty much like the case-when that you provided on your answer but without the count distinct).
Wrap that case statement with a MAX grouped by your column1. This will give you either a consistent 1 or 0 across all your different values of column1. You can use this value for your conditional formatting. The key here is to use the aggregated function with the group by.
You have here some oracle documentation on how to use the logical SQL group by.
Hope that helps! Good luck!

KDB+ / Q Syntax optimizations to oneliners

I am definitly a q-mortal. I would even say a q-baby. Well I have some question how to put together my code from separate lines to a one-liner. I guess there is a way more elegant solution than mine.
How to write the following statements in one line:
q)t1:(3#3)?\:`8
q)t1[;0]:`abc
In this table creation, how can I add another column which I have as list (like with the command ([]id:id_list;data:data_list;.....)). Till now I am creating another table and doing an inner join on them. I guess that's not very efficient:
`id xkey update id:i from flip (`row1`row2!(1 2;3 4))
For the 1st one you may do:
q)`abc,/:(3#2)?\:`8
abc jognjhck cihanjhp
abc hkpblald aeajbddp
abc blmjhgah ooeiogdj
For 2nd one you may treat the table as a dictionary:
q)tb
row1 row2
---------
1 3
2 4
q)(tb`id): 5 6
q)tb
row1 row2 id
------------
1 3 5
2 4 6
Two options:-
Create a 3*2 matrix of random symbols and append `abc in front.
q)`abc,/:(3#2)?\:`8
Or create 3*3 matrix of random symbols and use functional form of amend to update the first column. This is a more generic approach.
q).[(3#3)?\:`8;(::;0);:;`abc]
I don't see any problem with using just update statement.
q)c:1 2
q)t
row1 row2
---------
1 3
2 4
q)update newCol:c from `t
`t
q)t
row1 row2 newCol
----------------
1 3 1
2 4 2

What if the value of order field is the same for all the records [duplicate]

This question already has answers here:
Why does Oracle return specific sequence if 'orderby' values are identical?
(4 answers)
Closed 7 years ago.
All, Let's say the SQL looks like below.
Select a, b ,c from table1 order by c
If all the rows in table1 have the same field value in the field c. I want to know if the result has the same order for each time I executed the SQL.
Let's say data in the table1 looks like below.
a b c
-------------------------------------------
1 x1 2014-4-1
....
100 x100 2014-4-1
....
1000 x1000 2014-4-1
....
How Oracle determine the rows sequence for the same order by value?
Added
Will they be random sequence for each time?
One simple answer is NO. There is no guarantee that the ORDER BY on equal values will return the same sorted result every time. It might seem to you it is always stable, however, there are many reasons when it could change.
For example, the sorting on equal values might defer after:
Gathering statistics
Adding an index on the column
For example,
Let's say I have a table t:
SQL> SELECT * FROM t ORDER BY b;
A B
---------- ----------
1 1
2 1
3 2
4 2
5 3
6 3
6 rows selected.
The sorting on the column having similar values is just like:
SQL> CREATE TABLE t1 AS SELECT * FROM t ORDER BY b, DBMS_RANDOM.VALUE;
Table created.
SQL> SELECT * FROM t1 ORDER BY b;
A B
---------- ----------
1 1
2 1
4 2
3 2
5 3
6 3
6 rows selected.
So, similar data in bot the tables, however, ORDER BY on the column having equal values, dos not guarantee the same sorting.
They must not be random (change each time), but the order is not guaranteed (change sometimes).

Resources