Questions tagged [lead]

Accesses data from a subsequent row in the same result set without the use of a self-join in SQL Server 2017. LEAD provides access to a row at a given physical offset that follows the current row. Use this analytic function in a SELECT statement to compare values in the current row with values in a following row.

For further reading https://learn.microsoft.com/en-us/sql/t-sql/functions/lead-transact-sql

309 questions
0
votes
1 answer

How to select another column in table if first column doesnt have value that i need

I have 1 table where is 2 columns that i need to use at this moment( length and length_to_fault). If length has a null(N/A) value then i need to select value from length_to_fault and opposite. I also need to sort everything and i can do it with 1…
Cris
  • 17
  • 8
0
votes
1 answer

Returning reactivated users teradata sql

I am trying to form a query for returning, reactivated and WAU as defined below: Returning WAU - active last week WAU - not active last week, but active within last 30 days Reactivated WAU – not seen in 30+ days I have table for past 60 days…
0
votes
0 answers

JOIN ON second highest value (Impala)

I don't know how or even if this is possible.... I am trying to JOIN tables on the second highest value. I tried rowNumber, lag, lead & rank but haven't been able to get any of them to do what I need. To summarize, I'm just trying to shift the…
heat222
  • 99
  • 8
0
votes
0 answers

T-SQL Using Lead () function, but doesn't allow it in GROUP BY or in UPDATE

I am trying to insert some data from a different DB. And while doing my "insert", I am creating ExpirationDate, based on EffectiveDate column. My problem - I am using lead() function for that purpose. And if I leave that expression in my SELECT…
Hell-1931
  • 489
  • 1
  • 6
  • 24
0
votes
0 answers

Python code to create lead values for a variable across account with last value of an account as null

I have a a very large dataset containing id and data points of time series (with some missing values). The following is just an example. I will need to create a lead variable for a variable across groups built on account id such that last value…
0
votes
1 answer

Sub-Query Should return Null when comparing it to the Next rows from the different table

My T-SQL subquery returning more than 1 rows: WITH ReportView AS ( SELECT PMA.AssetName, ReleaseDt, ExpiresDt, TicketNumber, ChangeDt, ChangeReasonCd, ROW_NUMBER() OVER (PARTITION BY PMA.AssetName, ReleaseDt,…
tata
  • 33
  • 3
0
votes
2 answers

Compare prior row using time values

I have this set of data What I want to do is compare the Start time to the prior row and if the start time falls between the Start and end time of the prior row then flag it. Whether that flag is binary or x doesn't matter, just needs to be…
misterc625
  • 37
  • 2
  • 4
0
votes
2 answers

Creating next 4 lead features for every column in a data frame in R

I hava a very large dataframe with multiple readings (multiple columns) of more than 100 countries for 98 days each. There are several countries, several features and several dates in the real dataframe. I created a sample to illustrate my…
Yinkafad
  • 41
  • 5
0
votes
1 answer

Facebook leads ad missing fields

I am developing an App in Node.js for Lead Ad retrieval. Everything is working fine except, we recently realised that in the field_data we are missing some fields which are on Lead Add Form. The user data fields are on the first page of the form,…
MatnikR
  • 181
  • 2
  • 16
0
votes
1 answer

merging start and end date cycle dates

I have the below table. CUST_ID START_CYCLE END_CYCLE WORKER CUST_SUB_ID CUST_SUB_TYPE 101 1/1/2019 1/31/2019 ABC123 134 HIGH_SUB 101 2/1/2019 4/30/2019 ABC123 136 HIGH_SUB 101 5/1/2019 7/31/2019 …
Mr John
  • 231
  • 1
  • 3
  • 18
0
votes
2 answers

Count lead duplicate rows

I have the below table Table A: row_number id start_dt end_dt cust_dt cust_id 1 101 4/8/19 4/20/19 4/10/19 725 2 101 4/21/19 5/20/19 4/10/19 456 3 101 5/1/19 6/30/19 4/10/19 …
Mr John
  • 231
  • 1
  • 3
  • 18
0
votes
1 answer

How to predict churn for transactions grouped by same order_id in Google BigQuery SQL?

I am quite new to SQL in BigQuery. I am trying to predict customer status based on their order_id and date_start. Rules customer_status must be same for the same order_id The customer_status must be predicted based on the next Order_ID…
0
votes
0 answers

SQL Deriving A Date Range When Only One Date is Known and Other Date Is In Another Row

I have a situation in which I have two tables (examples below): As you can see, I do not have a Move Out Date. How could I create a view (SQL Server) that gives a range. For example, I will eventually need to use this view to see where each person…
Tyler H
  • 110
  • 9
0
votes
1 answer

SQL Server Lag and Lead

I'm using SQL Server 2014. I have a table: CREATE TABLE [dbo].tmpJobStatus ( [JobNum] [INT] NOT NULL, [Action] [VARCHAR](8) NULL, [ActionDate] [DATE] NULL, [SeqNum] [INT] NULL ) ON [PRIMARY] I have some data: INSERT INTO…
Michael
  • 2,507
  • 8
  • 35
  • 71
0
votes
1 answer

take lead values after filtering data

Below are results from a WITH statement I created: id prodid start end lead lag rnk_prod_first rnk_prod_last 1 4654 2/26/19 4/5/19 y null 1 7 1 4655 5/20/19 8/1/19 y …
John
  • 289
  • 3
  • 14