Skip to content
Advertisement

how do I group by in this select statement?

how do I group by contract_id? I’m using postgresql 9.6 new edit: So my aim here is to get the total nr of late days a contract_id has. and then also to show the rest of the information for that specific data point, hence I’m also selecting the rest of the columns in my table. Those columns I don’t wish anything to be done with. Just leave them as they are.

Advertisement

Answer

If you want one row per contract_id then you can use distinct on:

This returns the row with the latest duedate for each contract (that meets the where conditions of course).

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