Skip to content
Advertisement

Tag: aggregate-functions

Aggregate functions across multiple columns in postgres

I have a postgresql table with multiple fields containing integers (a1,a2,a3 etc). I want to run aggregate functions(mean, standard deviation etc) across more than one of the columns at once. (Some of them may have a reasonable number of nulls, so I don’t want to just generate column averages and then average those). I can get a set of integers

Problems with Postgresql CASE syntax

Here is my SQL query: When I execute the above query, I get this error: ERROR: CASE types record and integer cannot be matched From the error message I understand that PostgreSQL take the second select, respectively elapsed_time_from_first_login as a row, even if it will always be a single value (because of the min() function). Question: do you have some

GROUP BY and COUNT in PostgreSQL

The query: Returns n records in Postgresql: I just want to retrieve the number of records returned: 6. I used a subquery to achieve what I want, but this doesn’t seem optimum: How would I get the number of records in this context right in PostgreSQL? Answer I think you just need COUNT(DISTINCT post_id) FROM votes. See “4.2.7. Aggregate Expressions”

Advertisement