lianghsun/bird-text2sql-bench huggingface dataset:
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
List down all the person IDs who taught course ID of 18.

### Hint
person IDs refers to taughtBy.p_id; course ID of 18  refers to taughtBy.course_id = 18

### SQL
SELECT p_id FROM taughtBy WHERE course_id = 18
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
Provide the position status and IDs of professor who advised student ID "303".

### Hint
position status refers to hasPosition; IDs of professor refers to p_id_dummy; student ID "303" refers to advisedBy.p_id = 303

### SQL
SELECT T2.hasPosition, T1.p_id_dummy FROM advisedBy AS T1 INNER JOIN person AS T2 ON T1.p_id_dummy = T2.p_id WHERE T1.p_id = 303
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
List the person IDs and course levels of the affiliated professors in faculty.

### Hint
person IDs refers to person.p_id; affiliated professors in faculty refers to professor = 1 and hasPosition = 'Faculty_aff'

### SQL
SELECT T1.p_id, T3.courseLevel FROM person AS T1 INNER JOIN taughtBy AS T2 ON T1.p_id = T2.p_id INNER JOIN course AS T3 ON T3.course_id = T2.course_id WHERE T1.hasPosition = 'Faculty_aff'
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
Describe the year in program and in phase status for the student with most number in advisor.

### Hint
student refers to advisedBy.p_id; most number in advisor refers to max(count(p_id_dummy))

### SQL
SELECT T2.yearsInProgram, T2.inPhase FROM advisedBy AS T1 INNER JOIN person AS T2 ON T1.p_id = T2.p_id GROUP BY T1.p_id ORDER BY COUNT(*) DESC LIMIT 1
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
List down the advised student IDs and IDs of employing professor in faculty.

### Hint
advised student IDs refers to person.p_id; IDs of employing professor in faculty refers to p_id_dummy and hasPosition = 'Faculty_eme'

### SQL
SELECT T1.p_id, T2.p_id FROM advisedBy AS T1 INNER JOIN person AS T2 ON T1.p_id_dummy = T2.p_id WHERE hasPosition = 'Faculty_eme'
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
List the course IDs and levels of person IDs from 40 to 50.

### Hint
course IDs and levels refers to course.course_id and courseLevel; person IDs from 40 to 50 refers to taughtBy.p_id between 40 and 50

### SQL
SELECT T1.course_id, T1.courseLevel FROM course AS T1 INNER JOIN taughtBy AS T2 ON T1.course_id = T2.course_id WHERE T2.p_id BETWEEN 40 AND 50
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
Describe the course level and list of person IDs who taught course ID of 147.

### Hint
person IDs refers to taughtBy.p_id; course ID of 147 refers to course.course_id = 147

### SQL
SELECT T1.courseLevel, T1.course_id FROM course AS T1 INNER JOIN taughtBy AS T2 ON T1.course_id = T2.course_id WHERE T2.p_id = 141
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
Mention the person ID of faculty professor who taught course ID 104 and the course level.

### Hint
person ID refers to person.p_id; faculty professor refers to professor = 1 and hasPosition ! = 0

### SQL
SELECT T1.p_id, T3.courseLevel FROM person AS T1 INNER JOIN taughtBy AS T2 ON T1.p_id = T2.p_id INNER JOIN course AS T3 ON T3.course_id = T2.course_id WHERE T3.course_id = 104 AND T1.hasPosition <> 0
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
Find the professor ID and position in faculty who taught high-level undergraduate course of less than 10 in ID.

### Hint
professor ID refers to person.p_id when professor = 1; position in faculty refers to hasPosition; high-level undergraduate course refers to courseLevel = 'Level_400'; less than 10 in ID refers to course.course_id < 10

### SQL
SELECT T1.p_id, T1.hasPosition FROM person AS T1 INNER JOIN taughtBy AS T2 ON T1.p_id = T2.p_id INNER JOIN course AS T3 ON T3.course_id = T2.course_id WHERE T3.courseLevel = 'Level_400' AND T2.course_id < 10
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
List the professor ID who taught the course ID from 121 to 130 of basic undergraduate courses.

### Hint
professor ID refers to taughtBy.p_id; course ID from 121 to 130 of basic undergraduate courses refers to courseLevel = 'Level_300' and course.course_id between 121 and 130

### SQL
SELECT T2.p_id FROM course AS T1 INNER JOIN taughtBy AS T2 ON T1.course_id = T2.course_id WHERE T1.courseLevel = 'Level_300' AND T1.course_id > 121 AND T1.course_id < 130
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
List the advisor IDs for students with eighth year of program and position status in faculty of those professors.

### Hint
advisor IDs refers to p_id_dummy and person.p_id where professor = 1; eighth year of program refers to yearsInprogram = 'Year_8'; position status in faculty of those professors refers to hasPosition

### SQL
SELECT T1.p_id_dummy, T2.hasPosition FROM advisedBy AS T1 INNER JOIN person AS T2 ON T1.p_id = T2.p_id WHERE T2.yearsInProgram = 'Year_8'
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
List any five of course IDs with professor IDs who taught master courses.

### Hint
professor IDs refers to taughtBy.p_id; master course refers to courseLevel = 'Level_500'

### SQL
SELECT T1.course_id, T2.p_id FROM course AS T1 INNER JOIN taughtBy AS T2 ON T1.course_id = T2.course_id WHERE T1.courseLevel = 'Level_500' LIMIT 5
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
How many students are under advisor 415?

### Hint
advisor 415 refers to p_id_dummy = 415

### SQL
SELECT COUNT(*) FROM advisedBy WHERE p_id_dummy = 415
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
How many professional or master/graduate courses are there?

### Hint
professional or master/graduate courses refers to courseLevel = 'Level_500'

### SQL
SELECT COUNT(*) FROM course WHERE courseLevel = 'Level_500'
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
How many non-faculty members are not undergoing the phase of qualifications?

### Hint
non-faculty members refers to hasPosition = 0; are not undergoing the phase of qualifications refers to inPhase = 0

### SQL
SELECT COUNT(*) FROM person WHERE hasPosition = 0 AND inPhase = 0
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
Which professor taught the least amount of courses?

### Hint
professor refers to taughtBy.p_id; least amount of courses refers to min(count(course_id))

### SQL
SELECT p_id FROM taughtBy GROUP BY p_id ORDER BY COUNT(course_id) ASC LIMIT 1
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
Among the students being advised by Advisor 5, how many students are in the 5th year?

### Hint
Advisor 5 refers to p_id_dummy = 5; are in the 5th year refers to yearsInProgram = 'Year_5'

### SQL
SELECT COUNT(*) FROM advisedBy AS T1 INNER JOIN person AS T2 ON T1.p_id = T2.p_id WHERE T1.p_id_dummy = 5 AND T2.student = 1 AND T2.yearsInProgram = 'Year_5'
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
Which professor teaches the highest number of professional or master/graduate courses?

### Hint
professor refers to taughtBy.p_id; highest number of professional or master/graduate courses refers to max(count(taughtBy.course_id)) where courseLevel = 'Level_500'

### SQL
SELECT T2.p_id FROM course AS T1 INNER JOIN taughtBy AS T2 ON T1.course_id = T2.course_id WHERE T1.courseLevel = 'Level_500' GROUP BY T2.p_id ORDER BY COUNT(T2.course_id) DESC LIMIT 1
### Database Schema
CREATE TABLE course
(
    course_id   INTEGER
        constraint course_pk
            primary key,
    courseLevel TEXT
)

CREATE TABLE person
(
    p_id           INTEGER
        constraint person_pk
            primary key,
    professor      INTEGER,
    student        INTEGER,
    hasPosition    TEXT,
    inPhase        TEXT,
    yearsInProgram TEXT
)

CREATE TABLE "advisedBy"
(
    p_id       INTEGER,
    p_id_dummy INTEGER,
    constraint advisedBy_pk
        primary key (p_id, p_id_dummy),
    constraint advisedBy_person_p_id_p_id_fk
        foreign key (p_id, p_id_dummy) references person (p_id, p_id)
)

CREATE TABLE taughtBy
(
    course_id INTEGER,
    p_id      INTEGER,
    primary key (course_id, p_id),
    foreign key (p_id) references person(p_id),
    foreign key (course_id) references course(course_id)
)

### Question
Among the faculty affiliated professor, how many professors teaches professional or master/undergraduate courses?

### Hint
faculty affiliated professor refers to professor = 1 and hasPosition = 'Faculty_aff'; professional or master/undergraduate courses refers to courseLevel = 'Level_500'

### SQL
SELECT COUNT(*) FROM person AS T1 INNER JOIN taughtBy AS T2 ON T1.p_id = T2.p_id INNER JOIN course AS T3 ON T3.course_id = T2.course_id WHERE T1.hasPosition = 'Faculty_aff' AND T1.professor = 1 AND T3.courseLevel = 'Level_500'