lianghsun/bird-text2sql-bench huggingface dataset:
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
Please list the three episodes with the highest number of votes for the worst star rating.

### Hint
highest number of votes refers to MAX(COUNT(votes)); worst star rating refers to stars = 1

### SQL
SELECT T1.title FROM Episode AS T1 INNER JOIN Vote AS T2 ON T2.episode_id = T1.episode_id WHERE T2.stars = ( SELECT MIN(stars) FROM Vote ) ORDER BY T2.votes DESC LIMIT 3;
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
What was the character that Dan Castellaneta did the voice over for and was awarded?

### Hint
voice over for and was awarded refers to award like '%Voice-Over%';

### SQL
SELECT DISTINCT T2.character FROM Award AS T1 INNER JOIN Character_Award AS T2 ON T1.award_id = T2.award_id WHERE T1.award LIKE '%Voice-Over%' AND T1.person = 'Dan Castellaneta';
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
Please list all of the episodes that aired in 2008 that have the highest number of votes for the maximum star rating.

### Hint
aired in 2008 refers to air_date like '2008%'; highest number of votes refers to MAX(votes); maximum star rating refers to stars = 10

### SQL
SELECT T1.episode_id FROM Episode AS T1 INNER JOIN Vote AS T2 ON T2.episode_id = T1.episode_id WHERE SUBSTR(T1.air_date, 1, 4) = '2008' ORDER BY T2.votes DESC LIMIT 1;
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
What are the keywords of the episode "Take My Life, Please"?

### Hint
episode "Take My Life, Please" refers to title = 'Take My Life, Please'

### SQL
SELECT T2.keyword FROM Episode AS T1 INNER JOIN Keyword AS T2 ON T1.episode_id = T2.episode_id WHERE T1.title = 'Take My Life, Please';
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
Please provide any two episodes' names that have the same keyword of "1930s to 2020s".

### SQL
SELECT T1.title FROM Episode AS T1 INNER JOIN Keyword AS T2 ON T1.episode_id = T2.episode_id WHERE T2.keyword = '1930s to 2020s' LIMIT 2;
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
In 2010, which episode did Joel H. Cohen win an award for?

### Hint
In 2010 refers to year = 2010

### SQL
SELECT T2.title FROM Award AS T1 INNER JOIN Episode AS T2 ON T1.episode_id = T2.episode_id WHERE SUBSTR(T1.year, 1, 4) = '2010' AND T1.person = 'Joel H. Cohen';
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
How many votes of 5-star did the episode "Lisa the Drama Queen" receive?

### Hint
episode "Lisa the Drama Queen" refers to title = 'Lisa the Drama Queen';

### SQL
SELECT SUM(T2.votes) FROM Episode AS T1 INNER JOIN Vote AS T2 ON T2.episode_id = T1.episode_id WHERE T1.title = 'Lisa the Drama Queen' AND T2.stars = 5;
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
What is the number of votes for 10-star for the episode that has the keyword "reference to the fantastic four"?

### Hint
10-star refers to stars = 10

### SQL
SELECT T2.votes FROM Keyword AS T1 INNER JOIN Vote AS T2 ON T1.episode_id = T2.episode_id WHERE T2.stars = 10 AND T1.keyword = 'reference to the fantastic four';
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
What is the difference between the number of votes for 1-star vs. 10-star for the episode "The Burns and the Bees"?

### Hint
1-star refers to stars = 1; 10-star refers to stars = 10; episode "The Burns and the Bees" refers to title = 'The Burns and the Bees'; difference refers to SUBTRACT(votes when stars = 1, votes when stars = 10)

### SQL
SELECT SUM(CASE WHEN T2.stars = 10 THEN T2.votes ELSE 0 END) - SUM(CASE WHEN T2.stars = 1 THEN T2.votes ELSE 0 END) AS Difference FROM Episode AS T1 INNER JOIN Vote AS T2 ON T2.episode_id = T1.episode_id WHERE T1.title = 'The Burns and the Bees';
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
What are the keywords of the least popular episode?

### Hint
least popular episode refers to MIN(votes)

### SQL
SELECT T2.keyword FROM Episode AS T1 INNER JOIN Keyword AS T2 ON T1.episode_id = T2.episode_id ORDER BY T1.votes LIMIT 1;
### Database Schema
CREATE TABLE "Episode"
(
    episode_id       TEXT
        constraint Episode_pk
            primary key,
    season           INTEGER,
    episode          INTEGER,
    number_in_series INTEGER,
    title            TEXT,
    summary          TEXT,
    air_date         TEXT,
    episode_image    TEXT,
    rating           REAL,
    votes            INTEGER
)

CREATE TABLE Person
(
    name          TEXT
        constraint Person_pk
            primary key,
    birthdate     TEXT,
    birth_name    TEXT,
    birth_place   TEXT,
    birth_region  TEXT,
    birth_country TEXT,
    height_meters REAL,
    nickname      TEXT
)

CREATE TABLE Award
(
    award_id       INTEGER
            primary key,
    organization   TEXT,
    year           INTEGER,
    award_category TEXT,
    award          TEXT,
    person         TEXT,
    role           TEXT,
    episode_id     TEXT,
    season         TEXT,
    song           TEXT,
    result         TEXT,
    foreign key (person) references Person(name),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Character_Award
(
    award_id  INTEGER,
    character TEXT,
    foreign key (award_id) references Award(award_id)
)

CREATE TABLE Credit
(
    episode_id TEXT,
    category   TEXT,
    person     TEXT,
    role       TEXT,
    credited   TEXT,
    foreign key (episode_id) references Episode(episode_id),
    foreign key (person) references Person(name)
)

CREATE TABLE Keyword
(
    episode_id TEXT,
    keyword    TEXT,
    primary key (episode_id, keyword),
    foreign key (episode_id) references Episode(episode_id)
)

CREATE TABLE Vote
(
    episode_id TEXT,
    stars      INTEGER,
    votes      INTEGER,
    percent    REAL,
    foreign key (episode_id) references Episode(episode_id)
)

### Question
What are the episodes that have the average rating with more than 20 of 2-star votes?

### Hint
2-star refers to stars = 2; average rating refers to 5 < rating < = 7; more than 20 of 2-star votes refers to votes > 20

### SQL
SELECT DISTINCT T1.episode_id FROM Episode AS T1 INNER JOIN Vote AS T2 ON T2.episode_id = T1.episode_id WHERE T2.stars = 2 AND T2.votes > 20 AND T1.rating > 5.0 AND T1.rating <= 7.0;