Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Question about SQL Query
Message
De
26/06/2007 16:13:43
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
26/06/2007 13:59:30
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01235766
Message ID:
01235851
Vues:
16
>I have a table like so:
>
>
>ID |Date      |Rate
>1  |1/1/2007  |1
>2  |1/2/2007  |1
>3  |1/3/2007  |1
>4  |1/4/2007  |1.25
>5  |1/5/2007  |1.25
>6  |1/6/2007  |1.5
>7  |1/7/2007  |1
>8  |1/8/2007  |1
>9  |1/9/2007  |1
>10 |1/10/2007 |1.25
>11 |1/11/2007 |1.25
>12 |1/12/2007 |1.25
>13 |1/13/2007 |1.25
>14 |1/14/2007 |1
>15 |1/15/2007 |1
>16 |1/16/2007 |1
>
>
>I want a query that shows only when the rate changes... this would be my intended result:
>
>ID |Date      |Rate
>1  |1/1/2007  |1
>4  |1/4/2007  |1.25
>6  |1/6/2007  |1.5
>7  |1/7/2007  |1
>10 |1/10/2007 |1.25
>14 |1/14/2007 |1
>
>
>Would the best way be to include an inline query to query the current id - 1? Or is there some magic I can do to make it easier?

I solved my solution with this query:
SELECT 
	RNARatesID
	, EffectiveStartDate
	, WSJPrimeRate
FROM 
	RNARates
WHERE
	((SELECT WSJPrimeRate FROM RNARates x WHERE x.RNARatesID = RNARates.RNARatesID - 1) IS NULL)
	OR ((SELECT WSJPrimeRate FROM RNARates x WHERE x.RNARatesID = RNARates.RNARatesID - 1) <> RNARates.WSJPrimeRate)
It might not be the most efficient, but the user just changed their requirements so this might not even be needed anymore.
Very fitting: http://xkcd.com/386/
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform