bigquery aggregate table

yeshaswi yesaswi 1 Reputation point
2021-12-07T21:08:11.713+00:00

i have the below query:
create table table_new (date DATE,date_pst TIMESTAMP, customer_key INTEGER,
cust_org_num STRING,inward_schdeule INTEGER ,inward_count INTEGER ,
outward_schedule INTEGER,outward_count INTEGER,total_schedule INTEGER,total_schedule_ms INTEGER,schedule_zero INTEGER,schedule_nonzero INTEGER,
total_rides INTEGER,region STRING)
PARTITION BY date AS (
SELECT
date,
TIMESTAMP(create_time,"America/Los_Angeles") as date_pst,
customer_key,
cust_org_num,
region,

SUM(CASE ride_direction
WHEN 'Inward' THEN schedule
ELSE
0
END
) AS inward_schedule,
SUM(CASE ride_direction
WHEN 'Inward' THEN 1
ELSE
0
END
) AS inward_count,

SUM(CASE ride_direction
WHEN 'Outward' THEN schedule
ELSE
0
END
) AS outbound_duration,
SUM(CASE route_direction
WHEN 'Outward' THEN 1
ELSE
0
END
) AS outward_count,
sum(CASE WHEN schedule =0 then 1 else 0 end) as schdedule_zero,
sum(CASE when schedule>0 then 1 else 0 end)as schedule_nonzero,

SUM(schedule) AS total_schedule
SUM(schedule_ms) AS total_schedule_ms,
COUNT(1) AS total_rides,
region
FROM

'table'

WHERE date between start_date and end_date

AND schedule >=0
GROUP BY
date,
date_pst,
customer_key,
cust_org_num,
region);

but i want the know how i can get columns for below computaion :

1.Total ride Count = Non Zero ride Count + Zero ride Count
2Total schedule Sum

1.Inward ride Count = Inward Non Zero ride Count + Inward Zero ride Count
2.Inward schedule Sum

1.Outward ride Count = Outward Non Zero ride Count + Outward Zero ride Count
2.Outward schedule Sum

wanted to know i can get each of these columns from my query. thank you .

Developer technologies Transact-SQL
SQL Server Other
{count} votes

1 answer

Sort by: Most helpful
  1. Tom Phillips 17,771 Reputation points
    2021-12-08T18:14:30.53+00:00

    I suggest you post your questions on the Google BigQuery forum

    https://cloud.google.com/bigquery/docs/getting-support

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.