Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SPT SQL Syntax
Message
 
 
À
18/05/2011 14:28:29
Steven Dyke
Safran Seats USA
Texas, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01511013
Message ID:
01511014
Vues:
44
>This is hard to explain so I hope you can understand what I am trying to do.
>
>I have a parent table with recordindex, partno fields. This table can have multiple records with same partno.
>
>I have a child table with a recordindex, parentindex, datestamp, description, keycharacteristicvalue fields. This table can have many records of the same keycharacteristicvalue, one for each parent record of the same partno, one catch is the description is not always keyed in the same.
>
>Anyway I need a distinct list of the keycharacteristics with the latest date for a prticular partno along with the description field of each of those records.
>
>Example:
>
>Parent #1 has partno = 'A' with child records having a keycharacteristic = WEIGHT description = weight1 and a keycharacteristic = HEIGHT description = height1 completed on 05/10/2011
>Parent #2 has partno = 'A' with child records having a keycharacteristic = WEIGHT description = wght1 and a keycharacteristic = LENGTH description = lg1 completed on 05/12/2011
>
>So my list would have WEIGHT description wght1 and LENGTH description lg1 from Parent #2 and HEIGHT description height1 from Parent #1

SQL Server 2005+ specific syntax:
;with cte as (select C.*, 
row_number() over (partition by PartNo, KeyCharacteristicValue ORDER BY DateStamp DESC) as Row 
FROM Child C)

select * from cte where Row = 1
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform