Skip to content

Tag: postgresql

GROUP by data by time range in postgresql

I want to GROUP by data by time range. The example I have start_date and end_date, and I want the separate range between start_date and end_date on 25 range and get sum value from 1 to 25. Simple presentation of my table: table t1 have: generate_series function to separate on and sum by how this 25 for 2019-1…

Column concatenation in Order by expression. Is it wrong?

What are pros and cons whether I use Order by expression like this: or in this way: How each one does impact on performance? Answer The concatenation is unnecessary and may produce incorrect results. For instance, consider these values: The concatenation will put the first row first. By individual keys, it wi…

SQL select the latest record on joined tables

I want to retrieve the property which an user paid a tax last. have two tables person_properties and property_taxes What I tried so far: This gives me the person_id along the max year. But I actually need the property_id, the property which an user paid last. If I replace pp.person_id by pp.property_id, I the…