Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8760693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:06:37+00:00 2026-06-13T15:06:37+00:00

Hi I have an interesting problem. I Have an Employee Table AS Follows CREATE

  • 0

Hi I have an interesting problem. I Have an Employee Table AS Follows

CREATE TABLE EMPLOYEE(
EMPLOYEE_ID INTEGER,
SALARY DECIMAL(18,2),
PAY_PERIOD DATE)

Now the tables have employees some of whom get paid monthly,some weekly, some biweekly and some daily. What we want is to find an Indicator saying ‘Y’ if the salary of three consecutive Pay Periods is equal. Lets take the following example.

Employee   Pay_Period     Salary

  1         01/01/2012    $500
  1         08/01/2012    $200
  1         15/01/2012    $200
  1         22/01/2012    $200
  1         29/01/2012    $700

In this case the indicator should be Yes because 3 consecutive pay periods have a salary of $200.

Since the number of pay periods is not constant I am unsure of how to write this code because I do not know from before hand how many left joins I will need.Since I am writing this in Teradata I tried using the RECURSIVE Function but got stumped. Any general ideas on how to proceed with this?I would prefer not creating a stored procedure or having PL/SQL logic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:06:39+00:00Added an answer on June 13, 2026 at 3:06 pm

    Teradata may not support LEAD and LAG in the manner that Oracle and SQL Server now support it but the premise of these functions is based on selecting the correct window for your Window Aggregate functions. In Teradata LEAD and LAG can be accomplished by using the ROWS BETWEEN clause in your Window Aggregate Function.

    Here is how you can accomplish what you are looking to do using ROWS BETWEEN and a single pass at the table:

    CREATE VOLATILE TABLE myTable
    ( myID SMALLINT NOT NULL,
      PayPeriod DATE NOT NULL,
      PayAmount DECIMAL(5,2) NOT NULL)
    PRIMARY INDEX (myID) 
    ON COMMIT PRESERVE ROWS;
    
    INSERT INTO myTable VALUES (1, DATE '2012-01-01', 500);
    INSERT INTO myTable VALUES (1, DATE '2012-01-08', 200);
    INSERT INTO myTable VALUES (1, DATE '2012-01-15', 200);
    INSERT INTO myTable VALUES (1, DATE '2012-01-22', 200);
    INSERT INTO myTable VALUES (1, DATE '2012-01-29', 700);
    
    
    SELECT myID
         , PayPeriod
         , PayAmount
         , MAX(PayAmount) OVER (PARTITION BY myID 
                                    ORDER BY PayPeriod 
                                ROWS BETWEEN 1 FOLLOWING 
                                         AND 1 FOLLOWING) AS NextPayAmount_
         , MAX(PayAmount) OVER (PARTITION BY myID 
                                    ORDER BY PayPeriod 
                                ROWS BETWEEN 2 FOLLOWING 
                                         AND 2 FOLLOWING) AS NextPayAmount2_
         , CASE WHEN NextPayAmount_ = PayAmount
                 AND NextPayAmount2_ = PayAmount
                THEN 'Y'
                ELSE 'N'
           END PayIndicator_
      FROM myTable;
    

    Results

    1   2012-01-01  500 200 200 N
    1   2012-01-08  200 200 200 Y
    1   2012-01-15  200 200 700 N
    1   2012-01-22  200 700   ? N
    1   2012-01-29  700   ?   ? N
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting problem here. I have a MySql database table that has
I have interesting problem. I need to make tables in columns. Let me explain.
I have an interesting problem. I'd like to create a generic class that can
We have an interesting problem with WCF binding and streaming transfer mode that we
I have some interesting problem for an hour.. In my flex project, all width
I have an interesting problem. The basis of the problem is that my last
I have an interesting problem when using partial page update in asp.net with scriptmanager
I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
I have an interesting problem. I wrote the following perl script to recursively loop
I have an interesting problem here I've been trying to solve for the last

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.