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

SQL set TRUE if 5+ or more consecutive hours with values below 0

I want to check for 5+ consecutive hours hours were a given value is below 0, by setting a value (FiveConse) accordingly. Like shown in the table…
Watzhi
  • 1
0
votes
2 answers

Calculating difference between two timestamps in R; NA appears alongside time difference output

I am working to calculate the difference in hours between two timestamps in a dataframe. One timestamp is in the previous row i.e. lasttime and the other is in the leading row i.e. origtime. Here is a small…
metaltoaster
  • 380
  • 2
  • 15
0
votes
3 answers

SQL Server LEAD function

-- FIRST LOGIN DATE WITH CTE_FIRST_LOGIN AS ( SELECT PLAYER_ID, EVENT_DATE, ROW_NUMBER() OVER (PARTITION BY PLAYER_ID ORDER BY EVENT_DATE ASC) AS RN FROM ACTIVITY ), -- CONSECUTIVE LOGINS CTE_CONSEC_PLAYERS AS ( …
0
votes
1 answer

Oracle recursive CTE to check consecutive date rows

In trying to make use of a recursive common table expressions and lead analytical function that checks for 'N>1' consecutive absent_dates but seem to be struggling. Note I know the employees table isn't included in the query yet to obtain first_name…
Beefstu
  • 804
  • 6
  • 11
0
votes
1 answer

Get the previous row end date as the next row start date in POSTGRESQL

I have a table here with hire_date and effectivity_date of each employee which will be updated every time. I would like to get the previous row effectivity date as the next row start_date, and the end_date of the previous date will be minus 1 to…
JamesBowery
  • 71
  • 10
0
votes
0 answers

mariadb Lead() function not accepting today's date as default parameter

I am trying to use Lead/Lag function in mysql. In lead and lag function there is option to use default value for last non existent row. see documentation below LEAD(expr [, N[, default]]) [null_treatment] over_clause In above default value I want to…
Vijay
  • 2,021
  • 4
  • 24
  • 33
0
votes
0 answers

SQL Lead/Lag function in Excel Vba

Is there any particular format to use SQL Lag/Lead function in excel. I have written the following sql query but it is throwing syntax error sqlPivot = "SELECT [Type],[Year],[Value],Value-(LAG(Value , 1, 0) OVER(PARTITION BY [Type] ORDER …
0
votes
1 answer

Sequencing R, Time Series Data

I am looking to add a new column to my current data frame which adds a new sequencing number based on a string of events in a football match. This my current data frame head(test_P) index team.name possession_team.name minute second…
L.England
  • 153
  • 1
  • 1
  • 6
0
votes
1 answer

Problem when using HAVING with aliases in MySQL

I have a MySQL database with a table containing a list of dates. I need to find the first and last days in a gap in that table. They are the days off certain employee had in the last 30 days. I am using: Select DATE, LEAD(DATE,1) over(ORDER…
0
votes
1 answer

SQL) I can't seem to figure out how to compare successive rows in SQL using lead() method

My Database include every weekdays for each stocks…
koguma
  • 5
  • 3
0
votes
1 answer

R loop construction finding current rows based on previous and after information row

Well let's say we have the dataset below States <- data.frame(State=c( "HOT", "COLD", "MEDIUM", rep("HOT", 3), rep("COLD", 8), rep("MEDIUM", 6), rep(c("HOT", "COLD", "MEDIUM"), 9), rep(c("COLD", "HOT", "HOT",…
0
votes
1 answer

R lead lag function summarize within group and calculate percent

Here is what my data frame looks like: And here is the dput structure of it. structure(list(tier_1 = c("Organic Search", "Organic Search", "Organic Search", "Organic Search", "Organic Search", "Organic Search", "Organic Search", "Organic Search",…
hachiko
  • 671
  • 7
  • 20
0
votes
1 answer

capture reoccurring seventh day in new column

I have the below table... run_dt check_type curr_cnt 6/1/21 ALL 50 5/31/21 ALL 25 5/26/21 ALL 43 5/25/21 ALL 70 6/1/21 SUB 23 5/25/21 SUB 49 I would like to capture the value of…
Toby
  • 135
  • 2
  • 17
0
votes
0 answers

New Date Columns

I am having issues with a sql query and i'm not sure how i can get the results i need. Depending on the costctr and grade values, this determines the emp function. e.g emp 510 was L Production but is now L staff. I require two new columns - Valid…
Yasir
  • 79
  • 1
  • 5
0
votes
1 answer

Salesforce: Efficient way to automatically assign Lead Owner to specific User if Account or Company name is such

I am new to SF and learning things as I go. I am in a process to design automation for Lead Ownership assignment to specific User when Account or Company Name is 'X'. What should be the best approach Trigger, Workflow or Process Builder? Or do you…