Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Self Join
Message
De
03/07/2001 10:54:17
 
 
À
01/07/2001 22:14:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00525741
Message ID:
00526290
Vues:
18
>Hi all VFP users/experts
>
>I have a table as follows of employees salary data
>
>empl_no  WEF         Salary
>0001     01/01/1998  2000
>0001     01/01/1999  2500
>0001     01/01/2000  3000
>0001     01/02/2001  3200
>
>How can I construct a SQL to generate follwing cursor
>
>empl_no  WEF         New Salary     Old Salary
>0001     01/01/1998  2000           NULL
>0001     01/01/1999  2500           2000
>0001     01/01/2000  3000           2500
>0001     01/01/2001  3200           3000
>
>Would appreciate all help. Thanks


If you need to make this a little more generic so that any pattern of salary increases (multiple raises in a year, no raise in a year, etc.) can be displayed you might try something like
SELECT a.empl_no,a.wef,a.salary AS new_salary,b.salary AS old_salary FROM salary a;
LEFT JOIN salary b ON a.empl_no = b.empl_no AND a.wef > b.wef;
GROUP BY a.empl_no,a.wef
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform