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

Create a new variable using dplyr where, based on whether one variable has a specific value AND the previous or next value has a different value in R

I have data which looks like this df <- data.frame( ID = c(rep("A12345",5), rep("A23456",10), rep("A34567",5), "A45678", "A67891", rep("A78910",8), "A91011", rep("A10111",4), rep("A11121",3), "A12131", "A16731"), medication =…
Laura
  • 499
  • 5
  • 13
0
votes
2 answers

Incremental count

I have a table with a list of Customer Numbers and Order Dates and want to add a count against each Customer number, restarting from 1 each time the customer number changes, I've sorted the Table into Customer then Date order, and need to add an…
Gavin
  • 147
  • 2
  • 3
  • 13
0
votes
4 answers

Lag Lead to calculate the beginning and ending number of subscriptions in a period

I am trying to build a output table as given below. Can some one please help how I can use the lag lead or some other window function to solve it? Start= End from previous month Net= new- churn End = Start + Net INPUT month year new churn …
user286546
  • 187
  • 4
  • 12
0
votes
1 answer

Select row satisfying certain condition and rows next to it

Let's say I have a historical table keeping who has modified data ------------------------------------------------------------- | ID | Last_Modif | User_Modif | Col3,…
Kenny
  • 1,902
  • 6
  • 32
  • 61
0
votes
1 answer

Using LEAD to get next date

I need to create a query that answers the following question: I want to return the number of registrations that has a reading date of 26 days, number of entries that has a reading date of 27 days and there goes up to 31 days, the last 6 months. I…
Elton Santos
  • 571
  • 6
  • 32
0
votes
1 answer

How to use LEAD in SQL Server 2008

I have this script and it works in SQL Server 2012, but I need to use it in SQL Server 2008. Does anyone have a suggestion ? Create table #TempOne (ID int) Insert into #TempOne Values (1), (2), (34), (121), (72), (34), (81), (26), (234) Create…
0
votes
1 answer

Lead function in Hive

I am trying to retrieve the next "name1" after a specific "name2". For example, next "name1" after "complete2" in "name2" is "init3". This is the query I use, but it returns null. date_time name1 name2 …
user3447653
  • 3,968
  • 12
  • 58
  • 100
0
votes
1 answer

SQL Lead/Lag Smart Solution

I am working for a company that still uses MS SQL Server 2008 R2 and so I cant use Lead/Lag Functions. I know the general workaround of sub queries with partitions etc to replicate what this does but i am working on a project that requires lots and…
0
votes
2 answers

how to put a value in the first row of a group_by in R

I have a lot of different e-cars (car1 ... carN) with a state of charge (SOC) at the beginning ot a trip (start_trip) and the end (end_trip). Between to trips a car is loaded, to a maximum level. I know the charge capacity for the loading of a…
Rüdiger Kladt
  • 119
  • 1
  • 7
0
votes
0 answers

Next period lead function ssas calculation

I have encountered a problem with two calcultaions which I've managed to write - since I'm new to mdx ans ssas I suppose they could be written in a better way, unfortunately I do not know how to do this. My output is a table which looks as follow…
KejP
  • 5
  • 1
0
votes
1 answer

R lead and lag (shift) with times

I'm tried to use lag on a column of a data frame but when time is involved it just wont work. I've tried shift, lag and tlag. Example: y = strptime(sprintf("%s:%s:%s", 4, 20, 10), "%H:%M:%S") yy = strptime(sprintf("%s:%s:%s", 10, 20, 10),…
Olivia
  • 814
  • 1
  • 14
  • 26
0
votes
1 answer

How to use Analytic Functions in this query

I have a very unique query that I must write, and hoping to do it all in 1 query, but not sure if I can. I have a list of Articles, each article has a unique ID. The application passes this ID to the stored procedure. Then, I am to retrieve that…
Landon Statis
  • 683
  • 2
  • 10
  • 25
0
votes
1 answer

SAS: Marking next and previous observations with conflicts

I want to create dummies in SAS. My plan is, everytime AnnouncementDate ne . I want to make a variable called event=2 and the next one also (event=2) as well as the five previous observations 1 And all this flagged if the Previous 5 observations and…
MaBo88
  • 97
  • 1
  • 1
  • 9
0
votes
1 answer

How to write sql LEAD() and LAG() query in interbase?

This query gives the desired results when working with Oracle as my back-end. select field1, field2 from (select field1, field2, LEAD(field2) over (order by r) name from (select rownum r, …
Krishnarjun Banoth
  • 1,410
  • 1
  • 15
  • 30
0
votes
2 answers

Update Marketo lead's membership->progressionStatus using REST API

I'm trying to adapt https://github.com/Marketo/REST-Sample-Code/blob/master/php/LeadDatabase/Leads/SyncLeads.php for my own needs. I want to be able to update a lead's status from "Registered" to "Attended" using the REST API. (The Marketo Events…
Blazemonger
  • 90,923
  • 26
  • 142
  • 180