sql - Identify records with two identical values in two different columns? -
i have table of student id's, major1, major2 , minor. want identify records of students registered twice same major. need function select have same major "fin" in column major1 , major2. have far:
create view a5t5 select (firstname || ' ' || lastname)"fullname", studentid "studentid", major1 "doubledipping" a5 group major1, major2 ????? having count ????? order major,lastname,firstname; 
i think you're making harder is. if understand question correctly following query should give you're looking for:
select (firstname || ' ' || lastname) "fullname",        studentid "studentid",        major1 "doubledipping"   a5   major1 = major2 if need function, usual way return result set return opened sys_refcursor caller responsible closing. example:
create or replace function double_dipping_students     return sys_refcursor   csr sys_refcursor; begin   open csr select (firstname || ' ' || lastname) "fullname",                       studentid "studentid",                       major1 "doubledipping"                  a5                  major1 = major2;    return csr; end double_dipping_students; the above function might called pl/sql block as:
declare   csr       sys_refcursor;   strname   varchar2(2000);   nid       a5.studentid%type;   strmajor  a5.major1%type; begin   csr := double_dipping_students;    loop     fetch csr       name, id, major;      when csr%notfound exit;      dbms_output.put_line(strname || '  ' || nid || '  ' || strmajor);   end loop;    close csr; end; 
Comments
Post a Comment