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://docs.microsoft.com/en-us/sql/t-sql/functions/lead-transact-sql

228 questions
16
votes
3 answers

Lag() with condition in sql server

i have a table like this: Number Price Type Date Time ------ ----- ---- ---------- --------- 23456 0,665 SV 2014/02/02 08:00:02 23457 1,3 EC 2014/02/02 07:50:45 23460 0,668 SV …
user3292586
  • 169
  • 1
  • 1
  • 5
10
votes
4 answers

lead or lag function to get several values, not just the nth

I have a tibble with a list of words for each row. I want to create a new variable from a function that searches for a keyword and, if it finds the keyword, creates a string composed of the keyword plus-and-minus 3 words. The code below is close,…
wscampbell
  • 177
  • 7
10
votes
7 answers

Facebook page leadgen webhook returns error 102 Server Failure

Facebook page leadgen webhook won't work for my page and associated app. If I test the webhook I setup with the testing tool and click the "Track status" button, the issued realtime update object is associated to this error: 102 Server failure My…
AlexHv
  • 1,454
  • 12
  • 21
10
votes
4 answers

What's the opposite function to lag for an R vector/dataframe?

I have a problem dealing with time series in R. #--------------read data wb = loadWorkbook("Countries_Europe_Prices.xlsx") df = readWorksheet(wb, sheet="Sheet2") x <- df$Year y <- df$Index1 y <- lag(y, 1, na.pad = TRUE) cbind(x, y) It gives me…
Gilles Cosyn
  • 365
  • 1
  • 7
  • 16
10
votes
1 answer

SQL Server: Lead/Lag analytic function across groups (and not within groups)

Sorry for the long post, but I have provided copy & paste sample data and a possible solution approach below. The relevant part of the question is in the upper part of the post (above the horizontal rule). I have the following table Dt …
cryo111
  • 4,174
  • 1
  • 13
  • 32
9
votes
2 answers

How to use LEAD and LAG In Where?

i have a table like this: Number Price Type Date Time ------ ----- ---- ---------- --------- 23456 0,665 SV 2014/02/02 08:00:02 23457 1,3 EC 2014/02/02 07:50:45 23460 0,668 SV …
Salem Ahmed
  • 969
  • 2
  • 10
  • 17
7
votes
2 answers

Oracle - grouping values along interval

I need to query a table, containing a step id + value. The result will list the intervals, along with their associated value. Intervals here are defined as "succession of contiguous ids of steps, sharing same data value". I'm having a hard time…
6
votes
1 answer

Teradata equivalent for lead and lag function of oracle

I have been working ot see the equivalent function for Oracle lead and lag function. The oracle lead would look like LEAD(col1.date,1,ADD_MONTHS(col1.DATE,12)) OVER(Partition By tab.a,tab.b,tab.c Order By tab.a)-1 END_DATE LAG(col1.DATE +…
user708477
  • 147
  • 2
  • 4
  • 14
6
votes
2 answers

Comparing current Month and previous Month's rows on a column, SQL Server 2012

I need some guidance and help with a question I am not entirely sure how to solve in SQL Server 2012. I think LAG and LEAD functions could be useful but I am not sure. This is what my data looks right…
user3197575
  • 269
  • 5
  • 12
6
votes
4 answers

sql server lead - problems with date

I habe a problem with the new lead olap function in sql server 2012. CREATE TABLE Atext (id int, bez varchar(10), von date); GO INSERT INTO Atext VALUES (1, 't1', '2001-01-01'), (1, 't2', '2012-01-01'), (2, 'a1', '2020-01-01'), (2,'a1' ,…
JJANSSEN
  • 161
  • 1
  • 6
5
votes
0 answers

dplyr lead/lag with group_by

Do not understand why I the lead and lag functions ignore the group by. Here's a simple example (in reality I need to group by 5 columns). ​ # Dummy DataSet df <- data.frame(group = c("a","a","a","a", "a", "b", "b", "b", "b", "b"), …
Quixotic22
  • 86
  • 5
4
votes
1 answer

Calculating lead variable within mutate in R with dates

I am using dplyr's mutate function to create a POSIX date column of a data frame by taking the lead of another column. When I try to fill in the missing values in the lead function using a single date, I get an error: > dates # A tibble: 5 x 1 …
4
votes
1 answer

R: Is it possible to use mutate+lag with the same column?

I'm trying to replicate the following formula in R: Xt = Xt-1 * b + Zt * (1-b) I'm using the following code t %>% mutate(x= ifelse(week == 1, z, NaN)) %>% # Initial value for the first lag mutate(x= ifelse(week != 1, lag(x,1 ,default = 0) * b +…
JJ1603
  • 496
  • 1
  • 5
  • 16
3
votes
1 answer

R - logical statement with leads and lags

I have a vector of numbers and want to check whether there is any zero that is surrounded by two identical numbers e.g.: x <- c(3,0,3,4,5,2,0,1,3) any(x == 0 & lag(x) == lead(x)) TRUE The problem is however that if the vector starts or ends with…
3
votes
2 answers

How To Add Zoho CRM Leads with the Zoho CRM v2 API

How do I add a Zoho CRM Lead with the Zoho CRM v2 API, using simple curl connections? The docs are not very clear on not only how to add a lead, but how to even get the proper oAuth token to create the lead.
Volomike
  • 21,378
  • 19
  • 99
  • 188
1
2 3
15 16