There is a table tab1: |creation_date | acc_num | status| |——————-|———————|——-| |31.03.2021 07:43:43| 11111111111111111111| deny | |31.03.2021 07:43:43| …
Postgresql – access/use joined subquery result in another joined subquery
I have a database with tables for equipment we service (table e, field e_id) contracts on the equipment (table c, fields c_id, e_id, c_start, c_end) maintenance we have performed in the past (table m,…
window function rolling sum
I have a window function that gives me a rolling sum as below: but when some timestamps in the start_time column are equal the rolling sum stays the same, which makes sense bc I am ordering by start time, but it does not properly add the duration_seconds in the rolling sum as below: how can i fix or account f…
Calculate the number of unique strings with the date, with a possible error
In the select, I get rows from the table with time in the format TIMESTAMP. I want to count unique rows, BUT with a possible error of 1 second. In the example below, for example, 3 unique records (1 …
Determine persistent growth in value during a specific time range
Given the following data set example, how should I structure my SQL query to determine if the value has gradually grown day-by-day given a time range in the query for a specific user_id by returning a …
Determine growth in value in a specific time range
Given the following data set example, how should I structure my SQL query in order to determine if the value has grown over time (given a time range in the query) for a specific UserId by returning either a positive/negative growth percentage result or a true/false result UserId timestamp value 1 1617711825 3…
PostgreSQL: deadlock without a transaction
I have a route (in a node JS app) that inserts and updates some data in a PostgreSQL database (version 13). In pseudo-code, here are all queries that are done in sequential order: On some instances of the app without that much traffic that writes on their own table, I have many deadlocks. I don’t unders…
Jooq insert one2one and one2many relational data into 2 tables at once. How to deal with issues and rollback
F.e. model How to insert it at once in jooq? How to deal with rollback if some query will fail? Is it has to be programated on my side? I can not find a word about such case in documentation 🙁 Should Id do it manually like: find author id in db by name if author not exist insert new
Divide by zero error encountered error. Null value is eliminated by an aggregate or other SET operation
In this specific part of a SP I’m trying to create, I’m getting an error: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Divide by zero error encountered. Additional error <2>: ErrorMsg: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Warning: Null value is eliminated by an aggr…
Combining Values in a Column by Date
I have been tasked with writing this simple query and am not sure where to go from here. I am trying to create a report that shows 3 columns: Date_Column, Id_Column, & Amount_Col. The table for Id_Column has different IDs based on a location column (in the table, but not in my query below). For the report…