0

如果我必须比较两个游标并重新运行唯一的 val,我该怎么做

示例 CURSOR c_stock_option IS 选择 empid, name, ssn, isenrolled from employee where isenrolled=1

CURSOR c_espp_option IS 选择 empid, name, ssn, isenrolled from employee where isenrolled=2

现在我想拒绝光标 1 选择中的第二个光标中的所有记录,我该怎么做

4

1 回答 1

0

Ummm.....by definition, all of the rows where isenrolled=2 does not overlap with the rows where isenrolled=1. But I think you're asking a more general question about how to exclude rows from one result set that are in another.

If this is the case, you could take a few different approaches:

1)

CURSOR c_stock_option IS 
   Select empid, name, ssn, isenrolled from employee where isenrolled=1
   MINUS
   Select empid, name, ssn, isenrolled from employee where isenrolled=2

2)

CURSOR c_stock_option IS 
   Select empid, name, ssn, isenrolled from employee 
   where isenrolled=1
     and empid not in (
      Select empid, name, ssn, isenrolled from employee where isenrolled=2)

3)

CURSOR c_stock_option IS 
   Select empid, name, ssn, isenrolled from employee e
   where isenrolled=1
     and not exists(
      Select 1 from employee where e.empid = employee.empid and isenrolled=2)

Which you choose depends on your situation, data model, indexing etc.

于 2011-04-14T19:41:49.657 回答