home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / database / sybase / 362 < prev    next >
Encoding:
Text File  |  1992-11-19  |  3.0 KB  |  66 lines

  1. Newsgroups: comp.databases.sybase
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!news.columbia.edu!lamont!msolda
  3. From: msolda@lamont.ldgo.columbia.edu (M Solda)
  4. Subject: Re: multiple EXISTS subqueries under Sybase 4.8
  5. Message-ID: <1992Nov19.174435.25700@lamont.ldgo.columbia.edu>
  6. Keywords: EXISTS, 4.8, sun4, sunos 4.1.1
  7. Sender: news@lamont.ldgo.columbia.edu
  8. Reply-To: msolda@lamont.ldgo.columbia.edu
  9. Organization: Lamont-Doherty Geological Observatory
  10. References: <1992Nov14.174847.29576@lamont.ldgo.columbia.edu> <1992Nov15.144258.18635@panix.com> <1992Nov15.225853.2269@lamont.ldgo.columbia.edu> <1e8fj7INN1sg@gazette.bcm.tmc.edu> <1992Nov16.184540.11698@lamont.ldgo.columbia.edu> <1ee852INN90m@gazette.bcm.tmc.edu>
  11. Date: Thu, 19 Nov 1992 17:44:35 GMT
  12. Lines: 52
  13.  
  14. In article <1ee852INN90m@gazette.bcm.tmc.edu>, mparsons@fleming.csc.bcm.tmc.edu (Mark Parsons) writes:
  15. > In article <1992Nov16.184540.11698@lamont.ldgo.columbia.edu>, msolda@lamont.ldgo.columbia.edu (M Solda) writes:
  16. > |> > Ummmmmmm, if you're still working on it, could you post the example
  17. > |> > code?  I'm not quite following this.
  18. > |> > 
  19. > |> 
  20. > |> okay, here it is:
  21. > |> 
  22. > <UNIONed EXISTS and NOT EXISTS code deleted>
  23. > *blush* I should've said "post the original problem code", i.e., 
  24. > not the union version . . . 
  25.  
  26. here is the query that would not work:
  27.  
  28.  
  29.    select last_name, first_name, salary, title
  30.    from employee_id i1, salary_history s1, employee_status e1
  31.    where (
  32.              (exists (select *
  33.                       from salary_history
  34.                       where ss_num = s1.ss_num
  35.                          and comment = 'Employment'
  36.                          and salary_scope_begin <= '9/1/2'
  37.                          and salary_scope_begin > (select max(status_begin)
  38.                                                    from employee_status
  39.                                                    where status_begin < '9/1/2'
  40.                                                       and ss_num = s1.ss_num)))
  41.           or
  42.              (not exists (select *
  43.                           from employee_status
  44.                           where status_begin < '9/1/2'
  45.                              and ss_num = s1.ss_num))
  46.           )
  47.       and salary_scope_begin = (select max(salary_scope_begin)
  48.                                 from salary_history
  49.                                 where ss_num = s1.ss_num
  50.                                    and salary_scope_begin <= '9/1/2')
  51.       and employee_id.ss_num = salary_history.ss_num
  52.       and employee_id.ss_num = employee_status.ss_num
  53.       and status_begin is NULL
  54.       and title_effective_date = (select max(title_effective_date)
  55.                                   from employee_status
  56.                                   where title_effective_date <= '9/1/2'
  57.                                      and ss_num = s1.ss_num)
  58.    order by title, last_name
  59.    compute avg(salary), count(title) by title
  60.    compute avg(salary), count(title)
  61.  
  62. msolda
  63.