home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / database / oracle / 2621 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  2.9 KB

  1. Path: sparky!uunet!munnari.oz.au!metro!usage!sserve!hhcs.gov.au!geemic
  2. From: geemic@hhcs.gov.au
  3. Newsgroups: comp.databases.oracle
  4. Subject: Re: Explain THIS, please!
  5. Message-ID: <1992Dec23.150326.560@hhcs.gov.au>
  6. Date: 23 Dec 92 15:03:26 +1100
  7. References: <1gtd91INN7ln@ef2007.efhd.ford.com> <1992Dec22.163411.557@hhcs.gov.au>
  8. Distribution: world
  9. Organization: Aust. Dept. Health, Housing and Community Services
  10. Lines: 58
  11.  
  12. In article <1992Dec22.163411.557@hhcs.gov.au>, champs@hhcs.gov.au writes:
  13. > In article <1gtd91INN7ln@ef2007.efhd.ford.com>, wwm@ef5003.efhd.ford.com (Bill Meahan) writes:
  14. >> I'm tearing my hair out at the following:
  15. >> 
  16. >> SQL> l
  17. >>   1  select '%' Shift,
  18. >>   2   p.prefix||'-'||p.base_code||'-'||p.suffix||p.control_code PartNumber,
  19. >>   3   s.scrap_code Reason,
  20. >>   4   SUM(s.cost) TotalDollars
  21. >>   5   FROM cimcmms.scrap_count_history s, acg.part p
  22. >>   6   WHERE s.part_key=p.key
  23. >>   7    AND s.work_center_code = '75021'
  24. >>   8    AND s.production_date BETWEEN '1-Dec-92' AND '13-Dec-92'
  25. >>   9    AND s.shift LIKE '%'
  26. >>  10    AND s.part_key IN ( SELECT ss.part_key
  27. >>  11       FROM cimcmms.scrap_count_history ss
  28. >>  12       WHERE ss.work_center_code = '75021'
  29. >>  13        AND ss.production_date BETWEEN '1-Dec-92' AND '13-Dec-92'
  30. >>  14        AND ss.shift LIKE '%'
  31. >>  15        AND ROWID <11
  32. >                  *****
  33. > Did you mean ROWID or ROWNUM?
  34. >                 
  35. >>  16       GROUP BY ss.part_key
  36. >>  17       ORDER BY SUM(ss.cost) desc )
  37. >             **************************
  38. >             **************************
  39. > WARNING !  WARNING !  ORDER BYs DON'T WORK IN SUB-QUERIES
  40. > At least they don't in our version (VAX 3.0.9.7.1).  As soon as we put an order
  41. > by in a sub-query we got your error (group by worked fine though).  The SQL 
  42. > reference says you can't have order by in a sub-query on insert,update, and 
  43. > delete but does not say they're illegal in a select.
  44. > It looks to me like you're trying to retreive the 10 parts with the highest
  45. > sum(cost).  As far as I can tell it's impossible to retrieve the top 10 groups
  46. > of anything in a single query.  You can retrieve the top ten of something, but
  47. > not the top 10 GROUPS of something.  Your only chance is to use PL/SQL cursors
  48. > (though you'll have to put the results of the query in a temporary table so 
  49. > that you can see them after the PL/SQL has finished, as the results of PL/SQL 
  50. > statements don't echo to the screen).
  51. > Hope this helps.
  52. > ------------------------------------------------------------------------------
  53. >     /\       Steven Champness
  54. >    /  \      Dept Health Housing and Community Services
  55. >   /    \     Brisbane Queensland
  56. >  /      \     via
  57. > /   /    \   Canberra Australia
  58. > \  / /   /
  59. >  \/ / / /    MACINTOSH SOFTWARE AXIOM : If you need a manual to operate it
  60. >   \/ / /                                it wasn't designed properly in the
  61. >    \/ /                                 first place !
  62. >     \/
  63.  
  64.  
  65.  
  66.  
  67. Testing Steve... 
  68.