Advertisement

06.04.2007 at 03:31PM PDT, ID: 22612442
[x]
Attachment Details

Difference between rows within one column by Users (Teradata SQL or SAS)

Asked by Elmo_Yang in SQLBase, MS SQL Server, SAS

Tags: sql, difference, teradata, between, rows

I have a table with 3 columns as follows:
USERID          Date                                   SurveryScore    
123                01/01/06                             120
123                01/03/06                             200
123                01/05/06                             150
123                01/07/06                             220
234                01/05/06                             180
234                01/06/06                             190
345                01/02/06                             250
456                01/01/06                             110
456                01/04/06                             170
It's ordered by date for each User. For example, User 123 took 4 surveys on 4 days and had 4 scores. My questions is how to find out the difference between the scores for each user. I tried to solve the problem in Teradata SQL but I'm not familiar with procedures and I was told it's still gonna be hard since it's hard to tell the LOOP function how many loops to calculate the difference because each user has different number of surveys taken. Can anyone help me with it? I use Teradata SQL or SAS 9. So if you could help me in either environment, that'll be greatly appreciated. The ideal output would look like this:
USERID          Date                                   SurveryScore    Diff
123                01/01/06                             120                    0
123                01/03/06                             200                    80
123                01/05/06                             150                    -50
123                01/07/06                             220                    70
234                01/05/06                             180                    0
234                01/06/06                             190                    10
345                01/02/06                             250                    0
456                01/01/06                             110                    0
456                01/04/06                             170                   60

    Start Free Trial
[+][-]06.04.2007 at 04:31PM PDT, ID: 19213152

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2007 at 11:45PM PDT, ID: 19214994

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQLBase, MS SQL Server, SAS
Tags: sql, difference, teradata, between, rows
Sign Up Now!
Solution Provided By: itpuzzlesolver
Participating Experts: 4
Solution Grade: A
 
 
[+][-]06.07.2007 at 01:12AM PDT, ID: 19231604

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.11.2007 at 11:30AM PDT, ID: 19260374

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32