Skip to content

Tag: postgresql

Fill Array from another column SQL

I need help whit my Code (PostgreSQL). I get in my row Result {{2.0,10}{2.0,10}} but I want {{2.0,10}{3.0,20}}. I don’t know where my error is. Result is text [ ] its must be a 2D Array This is Table1 Nummer Name Result 01 Kevin This is Table2 Nummer Exam ProfNr 01 2.0 10 01 3.0 20 My Code is Answer

Finding max count of product

I am trying to find max count of product. The result must only display the brands which have max number of products in it. Can anyone suggest a better way to display result. Here are the table details: I have used this SQL query below but I am seeing an error below. The result must display the list of the

Insert records into one table using key from another table

I have a table with year, start and end columns like below. It has several years in it. Do not ask me why there is a year called 4 in there because I could not tell you. I just know that it cannot be removed from the table or else the web application will break. I use this query to

How to round timestamp to nearest day with postgresql

How can I round a timestamp to the nearest day in postgresql. I have tried using function date_trunc(‘day’, d_date::timestamp) but I get that is always staying in the same day. Example 1: Example 2: (This one works fine) Answer You could add 12 hours to the timestamp and then do the truncation tha…

Correct way to implement nested aggregation in PostgreSQL

I have a table that looks something like this: Multiple foo_id can belong to bar_id, and multiple timestamp can belong to foo_id What I want to do is to count the number of foo_id and the average length of foo_id (i.e. timestamp difference between the last and the first instance of the foo_id), belonging to t…