I am calculating a running balance and want to flag all rows till 0 value to have ‘MATCHED’ flag else ‘NOT-MATCHED’ flag with respect to account ID. Here is what I have tried but didn’t got proper result: Answer We can use a sub-query to find the last acct_rank which is 0 and then use case to test each row.
Tag: teradata
Changing In to Exists in SQL – with DISTINCT
Having this one: Reading this one: Changing IN to EXISTS in SQL Tried to change it into “Exists”, but produced this and it did not work: The error is 3706: Syntax error: expected something between ‘=’ and ‘DISTINCT’ keyword. Answer You have already redundant code. Inside the IN subquery you are selecting a column from ORGHEADER, so the LEFT join
Merging Respective Start and End Dates, Setting Flag Depending on Start/End Date – SQL
Problem: I have a table of transactions (see below) with either (open/start) or (close/end) transaction in the format of date. The task is to merge these transactions with their corresponding dates, however, there can be also cases when the transaction is opened/started, but not closed/ended, in which case only Start Date must be shown, and the Flag ‘Y’ assigned. The
How to get data from sub-table?
i have “transaction” table and it has date_of_transaction, transaction_number, item_number columns. it has rows. also i have “item” sub-table. they linked with “item_number”. there are item_name and item_category columns for “item” table. i want to print rows with item_name and transaction_number. how can i make it? Answer
How to generate dynamic table having begin month date and end month date Teradata or SAS SQL
I’d like to generate a dynamic Table with the start date of a month as a column and the end date of the month as another column. Ideally, I’d like to provide two years, f.e. 2016 and 2021. The output I’d like to have when providing these two years is the following: Kindly note that I require the output for
SQL logic to fail a check if any of the related customers has failed
I have the requirement to flag the customers Y only when all the related customers have also passed the check. below are the two tables: relationship table : Check table I want output like below: output justification: since 1,2,3 are related customers and since one of them (3) has n in table 2 , so all the related customers should
Select rowst where ID is on list and meet 2 other requirement, probably subquery in Teradata SQL?
I have table in Teradata SQL like below: And I have list of ID of clients: And I need to select ID of clients from table which are on myList and meet requirements: In col1 value is “A” or “B” In col2 value is bigger than 10 (>10) So as a result I need like below: Because ID = 111
Excluding same type of transactions within 3 seconds
For example, a table is like below Type Time Stamp Result 1 2021-06-25 14:21:00 A 1 2021-06-25 14:21:03 B 1 2021-06-25 14:21:06 C 1 2021-06-25 14:23:00 D 2 2021-06-25 14:21:02 C 2 2021-06-25 14:21:06 C 2 2021-06-25 14:21:09 D 3 2021-06-25 14:21:06 E And the result I want is as below. If there are a series of transactions with the
How to select rows from table 2 based on values in column from table 1 in SQL Teradata?
I have table in SQL Teradata: And I need to find only these clients which has their name (from column “client”) + “arg” or “por” in column “descpition” nevermind whether before or after name. So using above example I need to display only John Simon and Larry Fore, because they have their name in column “description + “arg” or “por”
Break ranges into rows Teradata
I have an input like this: I would link to break each range into rows: I’m trying to get this output in TERADATA, can you guys help me? Thanks a lot. Answer Teradata’s proprietary EXPAND ON syntax is for creating time series, but can used for your task, too. Assuming TD16.20+ this can be further simplified using a time series