从多行获取总计

时间:2019-09-05 09:07:04

标签: amazon-redshift

我想获取一列的总数,因为总数时我想做时在redshift中遇到问题。

这是我的代码

SELECT date(t.adjusted_booking_time),
datepart(week, t.adjusted_booking_time) as Week,

sum(CASE
WHEN t.booking_outcome IN (4,5,6) THEN 1
               ELSE 0
           END) AS Accepted_trips,
      count(DISTINCT t.driver_id) AS Active_drivers,
       count(DISTINCT t.customer_id) AS Active_customers,
 Sum(t.trip_gross_fare) AS GMV,
 sum(t.discount_applied) AS Discount,


FROM (select x.*, dateadd(hour, 2, x.booking_time) as adjusted_booking_time from analytics_v2.trips x)t
LEFT OUTER JOIN analytics_v2.customers c ON c.user_id=t.customer_id
LEFT OUTER JOIN analytics_v2.drivers d ON d.driver_id=t.driver_id
WHERE t.adjusted_booking_time BETWEEN '{{ Start_date }}' AND '{{ End_date }}' and t.country = 'sd' 
GROUP By date(t.adjusted_booking_time),week

0 个答案:

没有答案