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

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