teradata-sql-assistant

Aggregate periods using recursive queries

社会主义新天地 提交于 2019-12-13 03:29:56
问题 I need to merge overlapping periods (defined by FROM and TO variables) of sequential events (with identifier NUM) for each group (ID) with a "lookahead buffer", meaning that if the next period starts within the buffer zone, they should be merged. For instance; in the following example the second event (NUM = 2) starts at time 13, which is within the buffer zone (10 + 5 = 15). The tricky part here compared to other similar problems I've found is that although the buffer period has a fixed

Calculate time difference in Teradata

烈酒焚心 提交于 2019-12-13 03:24:04
问题 I have a scenario to calculate difference of timestamp in minute. There is one common field in 2 tables i.e dw_job_id and want to join 2 tables and guessing, calculate (scratch.COGIPF_RUNREPORT_test2.end_ts - concat(proct_dt, scratch.dw_job_sla_dim_test.sla_time) Example, Subtraction in minute: (2018-03-05 01:53:14.201000 - 2018-03-05 08:00:00.000000)= -366 It would be quite clear using below records: 1st query has end_ts: sel * from scratch.COGIPF_RUNREPORT_test2 where dw_job_id=1226 Result:

How to update a column only when last word of string matches a letter

梦想与她 提交于 2019-12-13 03:06:40
问题 I want to update columns(HostActvTyp and HostPrvTyp) when (HostCd) column last name is matching with last word of the string is "R" example string for host column "NXVR','REACTIVE', so the last word is R so we have to update to Reactive when it's N' to 'NEW' example "XVDN" enter image description here 回答1: seems you are looking for left or substr() update tablename set ActTyp = 'INDEPENDENT' where ActvTyp = left(your_value,1 ) 回答2: https://www.db-fiddle.com/f/bG4jZfnWksjc315eGTuG2k/1 UPDATE

Huge gap in increment value of identity column

江枫思渺然 提交于 2019-12-04 06:22:07
问题 I have created a table with an identity column. When I insert values in that table, Identity column shows huge gap of increment in between the values. Identity value jumps from 6 to 10001. This is the output ordered by Department id: Output Screenshot Here This is table I have created: Create Table STG2.Department ( DepartmentID int GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1 Cycle), Name varchar(100), GroupName varchar(100) ) PRIMARY INDEX (DepartmentID); This is how I am