Skip to content
Advertisement

Postgresql sum not working as expected when it is clear

I am solving the following Hard Leetcode SQL Question.

Link to Question: https://leetcode.com/problems/trips-and-users/ (You can directly look at the solution and understand the problem)

Question:

Trips table:

Users table:

Output:

Here’s my code:

And the output is:

How is the cancellation_rate is 0.00 when it is clear by looking at previous columns(s/c) that it should be 0.33,0.50, 0.00.

Advertisement

Answer

The good news is you’re only off by a typo.

In your example you are using cancelled_by_client or cancelled_by_client

rather than:

which would return:

request_at c s cancellation_rate
2013-10-01 3 1 0.33
2013-10-02 2 0 0.00
2013-10-03 2 1 0.50
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement