Skip to content
Advertisement

SQL group by is bringing lots of duplicates

I’m trying to group my data by OccDate, ParkingContextType, AuthorityId and of course, i would like to measure each sessions for each date/contexttype etc… However, I`m also trying to calculate the sum of sessions between a specific hour 8-18 for each date,ParkingContextType & AuthorityId.

The problem here is that 1 specific date is duplicated a lot and also the authority id etc… Something I’m doing wrong here and I cannot spot the problem,

Any one who can help me please?

Here is the SQL

This is the end result, which is wrong…I should have less OccDate, with Two parkingcontexttype OnStreet/OffStreet for each authority id… But apparently I have loads of them.

enter image description here

And a minimal result it should be:

Advertisement

Answer

You should use Aggregated function

Change SUM(OC.TotalRestrictedSessions) in Select and Remove TotalRestrictedSessions From Group By

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement