Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Max Qty
Message
 
 
À
28/02/2019 01:42:35
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
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01666828
Message ID:
01666839
Vues:
91
This message has been marked as the solution to the initial question of the thread.
>Sir While using SQLSERVER 2012, I have this data
>
>
>CREATE CURSOR table1(id n(3),qty n(5))
>
>INSERT INTO table1 values(1,500)
>INSERT INTO table1 values(2,600)
>INSERT INTO table1 values(3,700)
>INSERT INTO table1 values(4,3500)
>INSERT INTO table1 values(5,900)
>INSERT INTO table1 values(6,1200)
>INSERT INTO table1 values(7,1300)
>INSERT INTO table1 values(8,1500)
>INSERT INTO table1 values(9,1700)
>INSERT INTO table1 values(10,1800)
>
>INSERT INTO table1 values(11,1900)
>INSERT INTO table1 values(12,2000)
>INSERT INTO table1 values(13,2500)
>INSERT INTO table1 values(14,1600)
>INSERT INTO table1 values(15,1000)
>
>
>I Want to get maximum qty from the last 5 rows
>
>I need this row
>
>13 2500
>
>Please
;with cte as (select *, row_number() over (order by Id DESC) as RowIdDesc from Table1),

cte2 as (select *, row_number() over (order by qty DESC) as QtyOrd from cte where RowIdDESC <=5)

select Id, qty from cte2 where QtyOrd = 1; -- max qty for last 5 Ids
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform