Kusto dynamic table union (append if variable flag is set) [duplicate] - union

This question already has an answer here:
Kusto, Performing operations based on a condition
(1 answer)
Closed 9 months ago.
is the following logic possible in Kusto:
let flag = True;
let view = {
Table1
if flag:
| union
Table2
};
Thanks,

see: Kusto, Performing operations based on a condition
union (function1 | where flag), (function2 | where not(flag))

Related

Adding empty column in an array in google sheets [duplicate]

This question already has an answer here:
Virtually blank column in array?
(1 answer)
Closed 5 months ago.
I have this file with an input table in Google Sheets.
Keys
Tags
V1
V2
kEp
tag1
30
12
PgZ
tag2
8
2
pac
tag3
15
21
This is what i did; I added REGEXREPLACE(QUERY({A1:D},"Select Col1"),".+"," ") to get the empty column I
=ArrayFormula({
QUERY({A1:D}," Select Col1,Col2,Col3 ",1),
REGEXREPLACE(QUERY({A1:D},"Select Col1"),".+"," "),
QUERY({A1:D}," Select Col1,Col2,Col4 ",1)})
The ask
Is there is a simple way with the same range refrence this case A1:D to add an empty column to the array {} like this &""& ?
If 'empty' doesn't really have to be that empty, this is pretty simple...
=QUERY({A1:D4,A1:B4},"select Col1,Col2,Col3,' ',Col5,Col6,Col4 label ' '''")
You can try-
={QUERY({A1:D}," Select Col1,Col2,Col3 where Col1 is not null",1),
FLATTEN(SPLIT((REPT(" |",COUNTA(A:A))),"|")),
QUERY({A1:D}," Select Col1,Col2,Col4 where Col1 is not null",1)}
And simplified formula-
={QUERY(A:D,"select A,B,C where A is not null",1),
FLATTEN(SPLIT((REPT(" |",COUNTA(A:A))),"|")),
QUERY(A:D,"Select A,B,D where A is not null",1)}
Get different cuts of the range through OFFSET and join them along with empty arrays crafted with MAKEARRAY:
=LAMBDA(rg,where,how_many,
{
OFFSET(rg,0,0,,where),
MAKEARRAY(ROWS(rg),how_many,LAMBDA(r,c,)),
OFFSET(rg,0,where,,COLUMNS(rg)-where)
}
)(A1:INDEX(D:D,COUNTA(D:D)),1,2)

How to make SELECT in this case? [duplicate]

This question already has answers here:
Simplifying a query with a nested query
(3 answers)
Closed 1 year ago.
How to create a single MSSQL SELECT query in this case:
We've got 2 tables: fruits and expiration
The goal is to receive table where specific fruit number has information about having NULL in expirationDate column. Those fruit numbers that don't have NULL would have zeros in that column. Number 4 doesn't exist in expiration table, so it would also have 0 in results, because it doesn't have NULL.
Tables
You can't easily get the expiration date on the format you want. However, it does not really matter(?). I assume you want 1 or 0 in your new table because you want to use an if statement to check if the fruit is bad or not.
You can solve this easily:
if(expirationDate == null){/*something*/}
or, you might even be able to do
if(expirationDate) //this is all fruit that is not bad
else{/*your code to deal with expirated fruit here*/}
Note: I don't know what programming languages you are using. But in most of them: null and 0 are FALSE.
if(null) // false
if(0) //false
if(undefined) //false, in javascript
//everything that is not a false value, is true.
if("oiaehgtaoiwgneawg") //true
if(-1) //true
To answer your SQL query question:
You already have everything you need in the expiration table
SELECT fruit_number, expiration_date
FROM expiration;
I hope this helps 😊
You have to use it with Case Condition. But have to change statement a little:
select fruit_number, --distinct(fruit_number),
x =case expiration_date
when NULL then null
else 0
end
My friend found the solution.
SELECT
fruit_number,
MAX(expirationDate) as expirationDate
FROM
(SELECT
f.fruit_number,
CASE
WHEN e.expiration_date is NULL AND e.fruit_number IS NOT NULL THEN 1
ELSE 0
END AS expirationDate
FROM
expiration as e
FULL OUTER JOIN fruits as f ON f.fruit_number = e.fruit_number
WHERE
f.fruit_number IS NOT NULL
) t
GROUP BY
fruit_number
ORDER BY
fruit_number

How to select the item that has the greatest value in dataframe ? In Pyspark [duplicate]

This question already has answers here:
Find maximum row per group in Spark DataFrame
(2 answers)
Closed 1 year ago.
I would like to select the item that has the greatest value. For exemple in this table I would like to select MAC09
Identifiant
Val
MAC26
36
MAC10
9
MAC02
2
MAC32
11
MAC09
37
MAC28
10
there are several way of doing it, here is a solution using a rank
from pyspark.sql import functions as F, Window
df.withColumn("rnk", F.rank().over(Window.orderBy(F.col("Val").desc()))).where(
"rnk = 1"
).drop("rnk").show()
+-----------+---+
|Identifiant|Val|
+-----------+---+
| MAC09| 37|
+-----------+---+

select multiple values in case statement when using "in" [duplicate]

This question already has answers here:
SQL use CASE statement in WHERE IN clause
(7 answers)
Closed 5 years ago.
Im trying to figure out if is it possible to do a statement like this :
select * from telephone
where TEL_number like #tel_number
and TEL_cat in (case
when #tel_number_cat = 0
then 5
else 1 or 3
end)
Is there a way to do a select where TEL_number like #tel_number and if #tel_number_cat = 0 then TEL_cat = 5 else TEL_cat = 1 or 3
Is it possible to use CASE Statement in WHERE IN () clause but in the ELSE I need to get 2 category of numbers (1,3)
What about this:
select * from telephone
where TEL_number like #tel_number
and
(
(TEL_cat = 5 and #tel_number_cat = 0)
OR
(TEL_cat IN (1,3) and #tel_number_cat <> 0)
)

function to get only the integer [duplicate]

This question already has answers here:
Issue with Round function in ssrs
(3 answers)
Closed 8 years ago.
What function I have to use to get as a Result 1 in the following expression, in SQL Server or SSRS please
select ROUND((3 - (4 * 0.32)), 1) = 1.70
FLOOR is the function that you need: http://msdn.microsoft.com/en-us/library/ms178531.aspx
select FLOOR(ROUND((3 - (4 * 0.32)), 1))
ROUND((3 - (4 * 0.32)), 0)
=> 2
ROUND()
If that is not the desired result then you probably want to use FLOOR

Resources