home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / database / oracle / 1443 < prev    next >
Encoding:
Text File  |  1992-08-31  |  2.7 KB  |  76 lines

  1. Newsgroups: comp.databases.oracle
  2. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!destroyer!fmsrl7!ef2007!wwm
  3. From: wwm@ef2007.efhd.ford.com (William Meahan)
  4. Subject: Re: SQL*plus -- limiting maximum number of returned rows?
  5. Message-ID: <BtvEIC.Eo0@ef2007.efhd.ford.com>
  6. Organization: EFHD Ford Motor Company
  7. X-Newsreader: Tin 1.1 PL3
  8. References: <1992Aug31.204947.7478@news.iastate.edu>
  9. Distribution: usa
  10. Date: Mon, 31 Aug 1992 22:58:59 GMT
  11. Lines: 60
  12.  
  13. GO.MSB@isumvs.iastate.edu writes:
  14. : In article <BtuK40.8By@ef2007.efhd.ford.com>,
  15. : wwm@ef2007.efhd.ford.com (William Meahan) writes:
  16. : >In SQL*Plus (not embedded SQL!) is there any way of limiting the number
  17. : >of rows returned by a query?
  18. : >
  19. : >I am working on a report that is supposed to find the "top 5" items in
  20. : >a catagory.  The query returns 0 or more rows based on the selection
  21. : >criteria, sorted in the appropriate order.  Some queries return a dozen
  22. : >or more rows, but I'm only interested in the first 5.
  23. : >
  24. : >If I were using embedded SQL in a C program (or a perl script using
  25. : >oraperl) the solution would be trivial.  For internal reasons, however,
  26. : >I'm stuck with using SQL*Plus.
  27. : >
  28. : >Any ideas?
  29. : >--
  30. : >Bill Meahan                     |EFHD Information Systems Staff
  31. : >Technical Consultant            |Ford Motor Company
  32. : >wwm@ef2007.efhd.ford.com        | +1 313 487 6122
  33. : >...!fmsrl7!ef2007!wwm           |I'm not paid to speak for Ford!
  34. : ---------------------------------
  35. :   try   WHERE ROWNUM < 6
  36. : ALthough this works, I hate it.  If the query returns 2000 rows, it still
  37. : does and you wait for it to do so.  It then hands you the first 5 or whatever
  38. : you request.  ROWNUM is a pseudo-column and doesn't exist until some rows are
  39. : returned.
  40. : Marvin Beck    Iowa State University
  41.  
  42. Yep.  That'll do exactly what I _ASKED_ for, but not what I want :-(
  43. (don't you just hate it when your brain goes on vacation while you're
  44. entering a question into NetNews?)
  45.  
  46. The reality is more complex.
  47.  
  48. Consider the following records:
  49.  
  50.  
  51. Machine  Station   Fault   Count
  52. -------- --------  ------- -----
  53. Machine1 Station1  Code22  32
  54. Machine1 Station1  Code36  16
  55. Machine2 Station1  Code06  427
  56. Machine1 Station2  Code13  202
  57. ...
  58. etc.
  59.  
  60.  
  61. The select will return many rows with combinations of Machine, Station and
  62. Fault.  The trick is to select the "Top 5" Faults for EACH combination
  63. of Machine and Station based on the value of Count.
  64.  
  65. Much trickier, eh?
  66. -- 
  67. Bill Meahan            |EFHD Information Systems Staff
  68. Technical Consultant        |Ford Motor Company
  69. wwm@ef2007.efhd.ford.com          | +1 313 487 6122
  70. ...!fmsrl7!ef2007!wwm           |I'm not paid to speak for Ford!
  71. QUIT
  72.  
  73. ....!fmsrl7!ef2007!wwm           |I'm not paid to speak for Ford!
  74.