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

SQL Server banding timepoints based on value

I have audit data captured over time points which I would like to aggregate up to display where the value was the same over a period of time using SQL Server 2014. Taking the below example data I would like to transpose it to this ideally without…
Mark Ruse
  • 387
  • 1
  • 4
  • 12
2
votes
1 answer

Correct grouping sql

I am attempting to group some results in a table, by their id and name. For the group, I want to also select the next_id, the lead value of the next record that is part of the group. When I issue a query like this: SELECT id, grade, name, …
angryip
  • 2,140
  • 5
  • 33
  • 67
2
votes
1 answer

Trying to determine what the Next Machine Operation is for specific Part Numbers

I’m working with a table that contains Part number, Order of Operation and Machine Operations. The goal is to determine what the Next Machine Operation is for each part number. I’m able to do that with this example. SELECT MyTable.PARTNO…
2
votes
1 answer

Lead() and LAG() functionality in SQL Server 2008

Hope all the SQL GURUS out there are doing great :) I am trying to simulate LEAD() and LAG() functionality in SQL Server 2008. This is my scenario: I have a temp table which is populated using the base query with the business logic for mileage. I…
2
votes
1 answer

LAG/LEAD equivalent with grouping (SQL Server 2008 R2)

Note: I am using SQL Server 2008 R2 and built in LEAD/LAG functions are not available. I need to update a table's column to contain the 'previous' and 'next' values for ProductID - the table needs to store PrevProductID (LAG), ProductID and…
Maa421s
  • 159
  • 1
  • 12
2
votes
1 answer

Marketo Rest API - Update Leads using Id

How does one go about updating a lead using a lookupField of 'id'? I attempted to perform an update but received a '1003 - Field 'id' not allowed' error. Below is my request data for reference. { "action": "updateOnly", "lookupfield": "id", …
geoffo
  • 23
  • 4
2
votes
3 answers

Find clusters of time intervals

I have a table with multiple entries. One entry consists of start Datetime and end datetime. I want to find clusters of entries in such way that: If an entry starts before the prior entry ends then both are part of the cluster. It is some kind of…
tuxmania
  • 906
  • 2
  • 9
  • 28
2
votes
1 answer

Grouping subsequent dates into bins

Assuming I have the following table: date version 2015-02-01 v1 2015-02-02 v1 2015-02-03 v1 2015-02-04 v1 2015-02-02 v2 2015-02-03 v2 2015-02-08 v1 2015-02-09 v1 My query shall group dates in such way I get this…
tuxmania
  • 906
  • 2
  • 9
  • 28
2
votes
2 answers

Web Lead Forms in SugarCRM

Since the generated web lead forms in SugarCRM have the assigned_user_id same as the creator_user_id, the system doesn't send any mail notification. How to force SugarCRM to send a mail notification every time a lead is submitted without checking…
Roberto Aloi
  • 30,570
  • 21
  • 75
  • 112
2
votes
1 answer

Partition using Lead in Oracle

I am stuck on a problem to implement LEAD/LAG with partition. Below is the example and expected Result create table trd( key number, book number, prd_key number, direction varchar2(2), trdtime date, price…
cormalado
  • 21
  • 1
2
votes
4 answers

How to get start/end date from single date column -oracle

I've seen some brilliant answers on here and I am in need of a fix. I do not want to create table or ETL just yet and I was hoping to create a simple database view users could access to test first. A table has an item#, item_ticket_color#,…
C M
  • 21
  • 1
  • 3
2
votes
1 answer

SQL Server 2012 Lag and Lead Function

SQL Server 2012 Lag and Lead functions aren't performing well over large amounts of data, ~100 million records with ~200 columns. The combination of lag(balance, 1, 0) over (partition by loanId order by datetime series) trying to get previous…
kaiyan711
  • 171
  • 2
  • 7
1
vote
1 answer

Lead Function to Perform in DataStage

I am looking to do LEAD() and LAG() functions to perform in DataStage. Input C1 C2 1 100 2 200 3 300 4 400 Output - 1 C1 C2 C3 1 100 200 2 200 300 3 300 400 4 400 NULL Output - 2 C1 C2 C3 1 100 NULL 2 200 100 3 300 200 4 400 300 Please help me…
1
vote
1 answer

postgresql - find Discontinuous id and get read_time

I have a table like this, and there are three cases, ## case a | rec_no | read_time | id +--------+---------------------+---- | 45139 | 2023-02-07 17:00:00 | a | 45140 | 2023-02-07 17:15:00 | a | 45141 | 2023-02-07 17:30:00 | a | 45142…
hong
  • 13
  • 2
1
vote
2 answers

find the difference between current and previous value - postgresql

I'm trying to write a query that will show me the difference between the current value and the previous one from the query result. It seems to me that this can be done with the "OFFSET" or "LEAD" method. But I don't understand how. Исходная…
piolvi
  • 25
  • 5