Hello, first post here, but after reading other posts couldn't answer my question anywhere
I have 3 columns - ID, IP, Prod. Only ID could be sometimes blank
I would like to get unique combinations of ID-Prod, but when ID is missing to include IP instead
in simple excel formula, I am looking to do << if ( ID = "", IP & Prod , ID & Prod ) >>
So I couldn't find is null formula in metabase, so I tried finally this
Create a column for IDorIP by << = case ( ID > 0, ID , IP ) - but here is the first issue, there are instances where ID is not blank and still displayes the IP with the above formula.
I can then use concat ( IDorIP , Prod) , but this is already wrong because some ID's are automatically transferred to IP's and is not accurate
Separate note, I tried to do all in one column - concat ( case ( ID > 0, ID , IP ) , Prod ) - but this doesn't even work? Isn't it allowed to do 2 calculations in 1 expression?
So I think tried different approach
LEN = Length ( ID ) - first column
IDorIP = case ( LEN > 0, ID , IP ) - second column - works perfect, unlike the one above
Then third column concat ( IDorIP , Prod ) and I get an error:
Unknown column 'LEN' in 'field list'
The SQL code is this, so I hope someone can help because I am going in circles after couple of hours of trying
SELECT
source
.id
ASid
,source
.user_id
ASuser_id
,source
.user_ip
ASuser_ip
,
source
.merchant_id
ASmerchant_id
,source
.product_id
ASproduct_id
,source
.created_at
AScreated_at
,source
.updated_at
ASupdated_at
,source
.LEN
ASLEN
,source
.IDorIP2
ASIDorIP2
,source
.Prod-User
ASProd-User
FROM (SELECT char_length(
coupon_activation_history
.user_id
) ASLEN
, CASE WHEN
char_length(coupon_activation_history
.user_id
) > 0 THENcoupon_activation_history
.user_id
ELSEcoupon_activation_history
.user_ip
END ASIDorIP2
, concat(CASE WHENLEN
> 0 THEN
coupon_activation_history
.user_id
ELSEcoupon_activation_history
.user_ip
END,
coupon_activation_history
.product_id
) ASProd-User
,coupon_activation_history
.user_id
AS
user_id
,coupon_activation_history
.user_ip
ASuser_ip
,coupon_activation_history
.product_id
ASproduct_id
,coupon_activation_history
.id
ASid
,coupon_activation_history
.merchant_id
AS
merchant_id
,coupon_activation_history
.created_at
AScreated_at
,
coupon_activation_history
.updated_at
ASupdated_at
FROMcoupon_activation_history
)
source
LIMIT 1048576