I have a customer credit table and a booking table, shown below. I’ve executed the following query which works but it’s too simple. I now need to cross join my original query to the booking table so I can check for where the booking status is completed. My second query is wrong because it SUMs the adjustment for each booking.
Tag: postgresql
SQL group by a field and only return one joined row for each grouping
Table data What I want to do is group by the name, then for each group choose one of the rows with the earliest required by date. For this data set, I would like to end up with either rows 1 and 4, or rows 2 and 4. Expected result: OR I have something that returns 1,2 and 4 but
SQL – Conditionally join and replace values between two tables
I have two tables where one is holding “raw” data and another is holding “updated” data. The updated data just contains corrections of rows from the first table, but is essentially the same. It is a functional requirement for this data to be stored separately. I want a query with the following conditions: Select all rows from the first table
How to do select insert into statements and handling time series data and foreign keys?
I am completely lost on how to approach the problem I am having. I am trying to generate a boolean statement from one table and insert it into another table’s column. I am able to generate the boolean statement and create a new column as shown with the code and output below: This is what I have so far: I
Efficient way to simultaneously calc AVG and stddev_pop in postgres
stddev_pop() must be calculating AVG() as part of the full calc of standard deviation (unless there’s a shortcut I’m unaware of). for context, the goal is to test for the difference of means between …
Is there an alternative to WHERE COUNT () with Window Function in PostgreSQL?
I’m trying to do a grouping by two columns and filter the result only by records that don’t have the first column duplicated. Then the result values could be used as KEY and VALUE, respectively. I achieved the desired result in two different ways, but none of them seems to be adequate. To simplify the problem, I will summarize it
SQL query using Sum() and count() functions
I’m trying to query in PostgresQL using the SUM function to get the total of 3 different row types (Root, Dynamic, Test). I used the Sum() function for the first attempt and the Count() function for the second attempt; both didn’t work sadly. I expect a syntax error (since I’m a beginner at using SQL), but I’m not sure what
One-to-Many SQL SELECT concatenated into single row
I’m using Postgres and I have the following schemes. Orders Comments So, in this case, an order can have many comments. I need to iterate over the orders and get something like this: I tried to use LEFT JOIN but it didn’t work it returns this: Answer You are almost there – you just need aggregation: I would strongly recommend
Using global list in recursive SQL query to avoid visted nodes
I have a self-referential table User: Note that there are circular references. I want to get all the followers, and followers of the followers, and so on of a user such that all the followers are presented in a flattened list, with their respective depths For Adam: Problem I want to avoid the rows 3 and 4, which represents two
DB | Postgres | How to check if IP is in a list of IPs or a range
I have a table that has a TEXT column that holds IP, IPs or range (for example 1.1.1.1/24). In case of multiple IPs, the IPs will be separated by a @##@ for example 1.1.1.1@##@2.2.2.2 The table with 4 rows: I want to get all the rows that contain the ip 1.1.1.1 or 3.3.3.3, meaning I want to get the first