I'm using row_number() as a counter to see if there is any data with the conditions i specified. I want rows where p = 1 but I don't need the actual column that gives p=1 for every row. Is there any way I can exclude that column?
with base as(
select
state.simple as State,
customer_status,
cast(created_at as date) as Order_Date,
cast(dbt_valid_from as date) as Aktiv_Start_Date,
**row_number() over (partition by lower(email) order by dbt_valid_from) as p**
from analytics.fct_orders_all
left join `analytics.dim_customers_history` on
lower(customer.email) = lower(email)
where customer_status like "Aktiv%"
and state.simple = "pending"
and dbt_valid_from between created_at and timestamp_add(created_at, interval 14 day)
)
select *
from base
**where p = 1**
order by 4 desc
Big Query has a nice extension called SELECT * EXCEPT
:
with base as (...)
select * except(p) from base where p = 1 order by 4
BigQuery allows this using except
:
select b.* except (p)
from base b
where p = 1;
You can also use replace
to change the names of columns as well. These very handy modifiers are explained in the documentation .
you can always avoid using select *
I have a similar query here:
;with base as(
select
'Pending' as State,
a.preferredName,
cast(createDate as date) as Order_Date,
cast(birthdate as date) as Aktiv_Start_Date,
a.nationalitycode,
row_number() over (partition by a.nationalitycode order by a.nationalitycode) as p
from [app].[applicant] a
)
select *
from base
where p = 1
order by 4 desc
Putting the list of columns that I want to see
implicit in the select:
;with base as(
select
'Pending' as State,
a.preferredName,
cast(createDate as date) as Order_Date,
cast(birthdate as date) as Aktiv_Start_Date,
a.nationalitycode,
row_number() over (partition by a.nationalitycode order by a.nationalitycode) as p
from [app].[applicant] a
)
select
State,
preferredName,
Order_Date,
Aktiv_Start_Date,
nationalityCode
from base
where p = 1
order by 4 desc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.