Skip to content

Prevent NULLs on select average values

I’m trying to figure out how to prevent NULLs on return from a select and do not return anything (0 rows) for that query where I provide incorrect state value as select avg(lat) as lat, avg(lon) as …

SQL case statement when duplicate rows

Goal: col: id needs to be unique, no duplicates Issue: when id_catelog1 is null, id_catelog2 kicks in but makes multiple rows since some of them have multiple id_catelog2. For the multiple ones, I …

Second greatests running value with SQL

I have a table such as: n value 1 1 2 4 3 4 4 6 5 4 6 8 I can easily find the running max of this value: SELECT *, max(value) over (order by n rows unbounded preceding) as mx FROM table n …

SQL – get an AVG from a COUNT

how you doing? I’m trying to get the average from a count. The metric is a string, so I get an error. I’ve tried some ways, but I can’t. Thanks for your help This is the code This is what I’ve unsuccessfully tried AVG (newsletter) as percentage AVG (CAST (newsletter as INT64)) as perce…

HOW TO CHECK CONDITIONS FOR PREVIOUS MONTH

My table is like I am trying to get customer_ids where they didn’t do any transactions previous month and made transactions with at least 2 transaction_type at this_month.While doing this I am converting rundate to MM-YYYY format. What I’ve done for getting previous month and this month on MM-YYY …