Skip to content

Tag: sum

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 w…

SQL Insert into duplicates

My code is as follows: I should explain the SUM(), there are differing dates on schedule such as I want to get all the “count” of “serviceId” beyond today hence the ‘date >= GETDATE()’ Basically I want the table to look like so: I am able to get the values but I get them…

SQL SUM values by DISTINCT column after JOIN

I’ve been searching the forums for a solution for hours now but I couldn’t quite find the one that is fitting for my problem. I have two tables: members **************** id name city 1 John Boston 2 Maria Boston 3 Steve London 4 Oscar London 5 Ben Singapore donations ******************** member_id…