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
2
votes
0 answers

Create new CRM integration for Facebook Ads

We have a CRM for our applications, which provides services to other institutions which they have their own customers and users. We went through webhook integration for our own institution but the process is a little bit tricky. My question is how…
Navid Kianfar
  • 171
  • 1
  • 10
2
votes
12 answers

Why does my query return errors on Codility's test editor?

My solution to Codility / Exercises 6 SQL / SqlEventsDelta in SQLite works in local DB Browser but not in online Codility test editor. How can I solve this? I want to use my own SQLite code: WITH cte1 AS ( SELECT *, CASE WHEN e2.event_type =…
yunjeong park
  • 23
  • 1
  • 4
2
votes
1 answer

Effcient shifting in R data.table with missing values

I have a data.table with the following three variables receptionist = id of the reception person week.no = this week's number (1 means first week) absent.thisweek = number of days absent this week Note that we only have data for the weeks…
vivek
  • 301
  • 3
  • 13
2
votes
2 answers

Leading vector taking values based on future values of another vector

I have a sequence of treatments, one per day (binary), say: trt <- c(0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0) I want to create a new vector, which corresponds to each element of trt and indicates whether the NEXT three treatments are all 0. For example,…
bob
  • 610
  • 5
  • 23
2
votes
1 answer

MYSQL difference between two datetime

I have the following table. table1: id_user | action | time --------+--------+---------------------- 1 | 2 | '2009-05-18 11:45:42' 1 | 2 | '2009-05-18 11:45:45' 1 | 3 | '2009-05-18 11:45:50' 1 | 2 |…
2
votes
3 answers

SQL - Using LEAD to skip over rows with a certain condition

Using Standard SQL in Google BigQuery. I have a table with 2 order types: A and B. Id | Type | OrderDate ----------------- 1 | A | 2019-03-01 2 | B | 2019-03-04 3 | B | 2019-03-04 4 | A | 2019-03-05 5 | A | 2019-03-06 6 | B |…
cky_stew
  • 51
  • 3
2
votes
5 answers

Choosing a single row based on multiple criteria

Can anyone think how to how to do this in R? Simple data: seq<-c("A","A","A","B","B","B","B") rank<-c(1,2,3,1,2,3,4) match<-c("y","n","y","n","n","y","y") df<- as.data.frame(cbind(seq,rank,match)) seq rank match 1 A …
2
votes
2 answers

Lead and case expression

I have this table: ID Date ----------------- 1 1/1/2019 1 1/15/2019 Expected output: ID DATE LEAD_DATE ------------------------- 1 1/1/2019 1/14/2019 1 1/15/2019 SYSDATE SQL: SELECT *, CASE WHEN LEAD…
Mr John
  • 231
  • 1
  • 3
  • 18
2
votes
2 answers

How to add a flag to the rows after a specific value within a key in Oracle SQL?

I have the following data: Key Stage CreateDate AAF 0 01-Jan-2018 AAF 0 02-Jan-2018 AAF 0 10-Jan-2018 AAF 20 20-Jan-2018 AAF 40 20-Mar-2018 AAF 0 01-May-2018 AAF 0 10-May-2018 AAF 0 20-May-2018 AAF 30 20-Jun-2018 AAF…
CuriP
  • 83
  • 10
2
votes
1 answer

How to find delta for same number and name in pandas?

I have the below dataframe and I need to subtract and find the delta between next quater and current quater plus next to next quater and current quater. Input data: Number Name Year Quater value 1 an 2018 1 2.5 2 bn 2018 1 …
user3222101
  • 1,270
  • 2
  • 24
  • 43
2
votes
2 answers

Using lead and lag from dplyr for differential values within a vector

I have a data frame structure(list(Time = structure(c(1531056854, 1531057121, 1517382101, 1517386850, 1517386951, 1517399987, 1517400523, 1517400523), class = c("POSIXct", "POSIXt")), Data = c("Start", "Exit", "Start", "Start", "Exit", "Start",…
Apricot
  • 2,925
  • 5
  • 42
  • 88
2
votes
3 answers

lag function with variable n

I am having some problems using the lag function in dplyr. This is my dataset. ID <- c(100, 100, 100, 200, 200, 300, 300) daytime <- c("2010-12-21 06:00:00", "2010-12-21 09:00:00", "2010-12-21 13:00:00 ", "2010-12-23 23:00:00", "2010-12-24…
Huicong
  • 65
  • 1
  • 7
2
votes
1 answer

R lag/lead - how to ignore rows before and after existing rows

I have this dataframe in R id a b c d 1 42 3 2 NA 5 2 42 NA 6 NA 6 3 42 1 NA 7 8 With function like this library(dplyr) dataframe %>% …
2
votes
2 answers

LAG works, LEAD returning 1 within the same statement

I am puzzled over LEAD returning always ID=1, which is not even an ID in the table (ID start at ~18k), instead of a valid ID for the next record. NULL values are where they supposed to be, it's just the rows, which supposed to contain a valid ID.…
Oak_3260548
  • 1,882
  • 3
  • 23
  • 41
2
votes
1 answer

The lead list for a facebook campaign ad always returns empty

I'm creating a management that finds impressions, clicks, and leads for Facebook campaigns associated with my business account. For impressions and clicks, there were no problems but I can not find the leads. This is the code (taken from Facebook…
1 2
3
20 21