Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Maximum Qty
Message
From
24/01/2019 03:03:54
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows Server 2008 R2
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01665698
Message ID:
01665707
Views:
63
Likes (1)
>Sir all solutions provided from all participants work fine.
>
>Thanks for helping

You need to check if there are scenarios that can give a wrong result. Not sure if this data can happen, but this seems to give the wrong record
If you add records with large amounts in qty:

CREATE CURSOR junk(id n(3),qty n(5))

INSERT INTO junk values(1,500)
INSERT INTO junk values(2,600)
INSERT INTO junk values(3,700)
INSERT INTO junk values(4,700)
INSERT INTO junk values(5,700)
INSERT INTO junk values(6,700)
INSERT INTO junk values(7,700)
INSERT INTO junk values(8,700)
INSERT INTO junk values(9,700)
INSERT INTO junk values(10,800)
INSERT INTO junk values(11,900)
INSERT INTO junk values(12,1000)
INSERT INTO junk values(13,1100)
INSERT INTO junk values(14,1200)
INSERT INTO junk values(15,1300)
INSERT INTO junk values(16,1300)
INSERT INTO junk values(17,1300)
INSERT INTO junk values(18,1400)
INSERT INTO junk values(19,1300)
INSERT INTO junk values(20,1300)
INSERT INTO junk values(21,21000)

SELECT TOP 1 Junk.*;
FROM Junk;
INNER JOIN (SELECT TOP 1 *, Qty * Cnt AS OrdBy ;
FROM (SELECT Qty, COUNT(*) AS Cnt FROM junk GROUP BY Qty) aaa;
ORDER BY OrdBy DESC) jnk ON jnk.Qty = junk.Qty;
ORDER BY Id

Because Qty * Cnt assumes that there are never large differences in qty.
Christian Isberner
Software Consultant
Previous
Reply
Map
View

Click here to load this message in the networking platform