Skip to content
Advertisement

Tag: postgresql

pgsql merge two json arrays

I have to select two type of result set from a table and merge them in single json array like Its saying syntax error I believe due to order by. I need to return this in json array so I am trying like this Its retiring two json arrays i.e. obvious, How can I make this in single array Thanks,

PostgreSql Right Join From 3 Tables [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed last year. Improve this question I

Percentage calculation in SQL

I have some cars in a table along with the year they came out, and I’m trying to calculate the percentages of the cars that belong in the 4 following age groups: 0-4, 5-9, 10-19, 20+. I tried to do this in 3 different ways: 1. I got this error: I got this error: I got this error: Any ideas

Name of customers who are of legal age (18 years) Postgresql

I have a question about how to return only customers over 18 years old. I’m just getting back from the customers Answer If you want to filter the rows, use a where clause. If you want to filter by age, you can use date comparisons: Note that phrasing the condition this way makes it friendlier to indexes.

Postgres on Conflict Update With Default Column Expression

In case a column has a default value expression Is it possible for on conflict statement reset the column with the default expression without copy-paste the expression it self using default as a value while composing excluded record it self I.e. just to refer the default exactly from the update statement. Something like or even Answer Yes, you can use

How to group by fields which have specific value in SQL?

I have the following columns in my table (I’m using postgresql): parent, child, status. Each parent has 1 or 2 children. I want to select all parents whose first child has status x and second child has status y or in case there’s only 1 child than parent with child with status x. For example, a table with the following

How to achieve conditional array aggregate?

For simplicity I’ll use the following patient and appointment tables. What I want is one report that contains the following data. So what I need to do is: Get the patient names from patient table aggregate all appointment statuses of the patient aggregate all appointment times of appointments that have status=’active’ So the initial query that I created is: DBFiddle

Advertisement