Skip to content

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

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…