CREATE OR REPLACE VIEW `ifood-prev-fraude-case.fraude_biometria.vw_orders_daily` AS
SELECT Driver_ID,
  DATE(Order_Dt) AS Dt,
  COUNT(*) AS Total_Orders,
  COUNTIF(Order_Status = 'CANCELLED') AS Cancels,
  SAFE_DIVIDE(COUNTIF(Order_Status = 'CANCELLED'), COUNT(*)) AS Cancel_Rate
FROM `ifood-prev-fraude-case.fraude_biometria.orders_typed`
WHERE Driver_ID IS NOT NULL
GROUP BY Driver_ID,
  Dt;