I have a table such as i.id t.status 140 ‘DONE’ 140 ‘RUNNING’ 140 ‘READY’ 137 ‘FAILED’ 137 ‘DONE’ 137 ‘DONE’ 123 ‘DONE’ 123 ‘DONE’ Which is a result of this query: I want to somehow get the id 137, because it’…
SQL Exit scalar function prematurely
In SQL, you can exit the stored procedure prematurely with RETURN statement. However, when I try to apply the same principle to the scalar function, it returns the error, since function needs to return something. How do I prematurely exit the scalar function the same way RETURN is used in the stored procedure…
SQL an ID in one group and an id from another
I have a request where I need a count where a participant completed an activity under one id (the gateway to completing other things) and then an id in a list of other ids. Right now, this code is only coming back with the the a count of the one id but not saying that one id complete + the
For rows with the same A, B, C values, how to select only “earliest” row (specified by column D) within a given time range?
I currently have a query (simplified below): Basically, the data source we’ve been getting data from writes their timestamps as when their job finished running rather than when the data actually came in (we can’t do anything about this on our end). Their jobs regularly end at 5-6 minutes after the…
ID which is available in table1 but not available in table2, check it date wise [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed last year. Improve this question Questio…
How does i/o on database relate to query type
So I have metrics that look like this. And here is my dumb question… Does the rw i/o directly correlate to rw query? Using the example below, does that mean there was increased read query activity? I don’t have some flags enabled yet to have metrics on the transaction level, but i’ll eventua…
How to join two tables where Columns are not matching in SQL
I have two different tables and in the select query I need to bring the SUM of the other column but both the tables have some similar data but still in the query output values are not coming fine. I am using below query :- Query 1 Query 2 Query 1 output COUNTRY BUDGET_SALES MY 20463355.16 SG 41095952.67 Query…
Percentage of tardiness and first date for defaults in postgresql
I have a table where I register a debt and the paid date: CREATE TABLE my_table ( the_debt_id varchar(6) NOT NULL, the_debt_paid timestamp NOT NULL, the_debt_due date NOT NULL ) INSERT …
Query to calculate “trailing twelve-month sum(column)” for 100s of dates in one query?
I have this table: Dividends History Table I’m trying to figure out the most efficient way to get: One row for each date Each row contains the sum(dividends_received_value) for the past year of data relative to the date in that row (“trailing twelve months”) Can this be done purely in SQL? I…
PostgreSQL create index on JSONB[]
Consider a table defined as follows: How can I create an index on json key type and how can I query on it? Edit: Previously, there were no indexes on json keys and select queries used an unnest operation as shown below: The problem is, if the table has a large number of rows, the above query will not only