1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| CREATE TABLE dbo.prix (
ReferencePrix uniqueidentifier primary key not null default (newid()),
ProduitID uniqueidentifier not null default (newid()),
ReferencePartenaire uniqueidentifier not null default (newid()),
Prix decimal (10,2))
GO
INSERT INTO dbo.prix (prix) values (10)
INSERT INTO dbo.prix (prix) values (20)
INSERT INTO dbo.prix (prix) values (30)
INSERT INTO dbo.prix (ProduitID, ReferencePartenaire, prix)
SELECT ProduitID, ReferencePartenaire, prix * 2
FROM dbo.Prix
INSERT INTO dbo.prix (ProduitID, ReferencePartenaire, prix)
SELECT ProduitID, ReferencePartenaire, prix * 2
FROM dbo.Prix
GO
SELECT ProduitID, ReferencePartenaire, prix
FROM (
SELECT *,
rank() over (partition by ProduitID order by prix) as rang
FROM dbo.Prix) t
WHERE t.rang = 1 |
Partager