My table is like: And I should get result as 2021-03-05 for march, and 2021-05-06 for may. So every month I should get the 4th row as date result. Answer You can use row_number(). But the real trick are the date functions. Let me assume that your database supports year() and month():
SQL Query for grouping within a segment with a condition
We need to select all the columns. Condition: Within a single MAT+PLANT If any vendor crosses 80% we take records of that vendor only and reject other records within that MAT+PLANT. If within a single MAT+PLANT If all the vendors have below 80%, we consider all the records. As shown in the image: Have attache…
Returning multiple identical rows in LISTAGG query
I’m using Oracle, and want to connect two tables into one select statement (for a report), and we’re required to concatenate some of the data from one table into a single row – for which I’m expecting to use LISTAGG. Simplified version of the problem: ACCOUNTS table: InitialDate Accoun…
SQL cumulative sum with mutilple conditions
I have a input table as this: I would like to calculate the cumulative sum of the flag for each, but the calculation should be refreshed if the flag is equal to 0 once again. So, the output table should be: So, any suggestion to solve this issue? I tried with this: But i have no idea how can I
Getting Incorrect results for selecting values between 2 dates
I am trying to run the below query to select some results between 2 dates but I am getting results as the condition doesn’t exist. So what is wrong here? Answer You are comparing dates with strings; the dates are converted to strings to do that comparison. From the documentation: During SELECT FROM oper…
What is the proper way of selecting multiple scalars within the same “using” statement with Dapper?
I have wrote the following method, which I hoped to make the method run faster by executing the tasks in parallel: Unfortunately, I receive the following exception: System.InvalidOperationException: ‘BeginExecuteReader requires an open and available Connection. The connection’s current state is co…
SQL adding data into 1 row using while loop
I need to get data into the same row in SQL, I am using a while loop. This might not be the right option. What I need to do is get all the data into one row. The code I have is adding a new row through each iteration. So first row must have data in column 1 through 5
Show a string that contains two numbers in SQL [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question I’m studying SQL just recently and I have encountered a problem. I want to show the Addr…
No more spool space in Database (Teradata)
I am a beginner in SQL and I have a problem with one of my queries on Teradata. When I run it, I get this error: “No more spool space in Database”. According to my research on the Internet, the problem would come from the fact that my query is not optimized enough, except that I don’t see ho…
Google BigQuery Federated Query connection Error
I am trying to use the Federated Query functionality in BigQuery to query some data from my Cloud SQL Postgres DB. Unfortunately I get the following error: It is quite similar to the error discussed here, but it was not solved (the word that appears in the quotes is different though): Connection Error while r…