A SQL quiz, tough one
From: L. Tseng <lesliet_at_u.washington.edu>
Date: 1997/04/19
Message-ID: <5j92dr$q0i_at_nntp6.u.washington.edu>#1/1
Date: 1997/04/19
Message-ID: <5j92dr$q0i_at_nntp6.u.washington.edu>#1/1
[Quoted] Hi, SQL experts,
[Quoted] There is a non-trivial SQL question for you... In the following code, what I intend to do is to select top 10 users with most network traffic volume and insert it into a table in DESC order for reporting purpose. [Quoted] as you can see, I marked two lines off because 'ROWNUM <= 10' clause generates a wrong data set and 'ORDER by' clause is not legal in a INSERT. So, any smart solutions for this?
Thanks for your help.
Leslie
INSERT INTO ReportTable ( LogID, GroupName, NetUser, Volume, ) SELECT NameID, GroupName, Name, SUM(BytesIn + BytesOut) FROM TableA, TableB, TableC, TableD WHERE .... ... .. -- AND ROWNUM <= 10 GROUP BY NameID, GroupName, Name; -- ORDER BY 4 DESCReceived on Sat Apr 19 1997 - 00:00:00 CEST