I want to get the least of prices from different suppliers and the name of the supplier. The least should be greater than zero(0). I have been able to get minimum value if zero is not in the list. For …
Query to mark if a value falls between a set of values
I have two tables. And I want to check if a value from one, falls between any two numbers in the other table. For example the tables are: table_a: +——–+——-+———————+ | name | …
Group objects by a sum of their references with a max limit
I am looking to aggregate IDs from a table by chunks from their reference from an other table. It is a bit hard to summary my problem so I will give an example: I have two tables, the table Box and …
Calculate the rank and apply it following an order
I want to calculate the dense rank over a group by clause and set my rank in order of my line id i.e the smallest ids get the first rank and so on. I am able to retrieve the dense rank of my lines …
Reverse group by and counts
I have tables for questions and answers. Each question can have 0 or multiple answers. When you left join the tables you get something like this: q1 a1 q1 a2 q2 a3 q3 NULL q4 NULL q5 a4 …
SQL getting balance point of two cumulative sums
Bellow I provide a code, which does the job on this interesting task to some extent, but may be poorly designed due to my SQL knowledge limits. The main problem is, that the query gives random (more …
SQL to concatenate all Query rows into one row
I have seen the following questions but can’t get them to work for what I’m looking for. How can multiple rows be concatenated into one in Oracle without creating a stored procedure? SQL Query to …
How to use a subquery in array_agg without using a join [closed]
I have a query that I would like to write wihout using a join and concat all phone numberes together from another table. The phone numbers are linked together by ink_id field. I tried these query but …
How to cut one row to starttime and endtime to mutiple day spend hour rows
Question: How to cut one row to starttime and endtime to mutiple day spend hour rows Table Data and DDL: starttime , endtime 2019/05/03 08:00:00 , 2019/05/05 12:00:00 CREATE TABLE T (“…
How to get row number for each null value?
I need to get row number for each record of null by sequence. Restart number when get a value in the row. I have tried so far select * , ROW_NUMBER() over (order by id) rn from @tbl select * …