Chinastark/bird_dataset huggingface dataset:
Database: computer_student
Note: student refers to advisedby.p_id; most number in advisor refers to max(count(p_id_dummy));
Question: Describe the year in program and in phase status for the student with most number in advisor.
SQL: SELECT person.yearsinprogram, person.inphase FROM advisedby INNER JOIN person ON advisedby.p_id = person.p_id GROUP BY advisedby.p_id ORDER BY count(*) DESC LIMIT 1
Database: computer_student
Note: advised student IDs refers to person.p_id; IDs of employing professor in faculty refers to p_id_dummy and hasposition = 'Faculty_eme';
Question: List down the advised student IDs and IDs of employing professor in faculty.
SQL: SELECT advisedby.p_id, person.p_id FROM advisedby INNER JOIN person ON advisedby.p_id_dummy = person.p_id WHERE hasposition = 'Faculty_eme'
Database: computer_student
Note: 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;
Question: List the course IDs and levels of person IDs from 40 to 50.
SQL: SELECT course.course_id, course.courselevel FROM course INNER JOIN taughtby ON course.course_id = taughtby.course_id WHERE taughtby.p_id BETWEEN 40 AND 50
Database: computer_student
Note: person IDs refers to taughtby.p_id; course ID of 147 refers to course.course_id = 147;
Question: Describe the course level and list of person IDs who taught course ID of 147.
SQL: SELECT course.courselevel, course.course_id FROM course INNER JOIN taughtby ON course.course_id = taughtby.course_id WHERE taughtby.p_id = 141
Database: computer_student
Note: person ID refers to person.p_id; faculty professor refers to professor = 1 and hasposition ! = 0;
Question: Mention the person ID of faculty professor who taught course ID 104 and the course level.
SQL: SELECT person.p_id, course.courselevel FROM person INNER JOIN taughtby ON person.p_id = taughtby.p_id INNER JOIN course ON course.course_id = taughtby.course_id WHERE course.course_id = 104 AND person.hasposition <> 0
Database: computer_student
Note: 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;
Question: Find the professor ID and position in faculty who taught high-level undergraduate course of less than 10 in ID.
SQL: SELECT person.p_id, person.hasposition FROM person INNER JOIN taughtby ON person.p_id = taughtby.p_id INNER JOIN course ON course.course_id = taughtby.course_id WHERE course.courselevel = 'Level_400' AND taughtby.course_id < 10
Database: computer_student
Note: 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;
Question: List the professor ID who taught the course ID from 121 to 130 of basic undergraduate courses.
SQL: SELECT taughtby.p_id FROM course INNER JOIN taughtby ON course.course_id = taughtby.course_id WHERE course.courselevel = 'Level_300' AND course.course_id > 121 AND course.course_id < 130
Database: computer_student
Note: 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;
Question: List the advisor IDs for students with eighth year of program and position status in faculty of those professors.
SQL: SELECT advisedby.p_id_dummy, person.hasposition FROM advisedby INNER JOIN person ON advisedby.p_id = person.p_id WHERE person.yearsinprogram = 'Year_8'
Database: computer_student
Note: professor IDs refers to taughtby.p_id; master course refers to courselevel = 'Level_500';
Question: List any five of course IDs with professor IDs who taught master courses.
SQL: SELECT course.course_id, taughtby.p_id FROM course INNER JOIN taughtby ON course.course_id = taughtby.course_id WHERE course.courselevel = 'Level_500' LIMIT 5
Database: computer_student
Note: advisor 415 refers to p_id_dummy = 415;
Question: How many students are under advisor 415?
SQL: SELECT count(*) FROM advisedby WHERE p_id_dummy = 415
Database: computer_student
Note: professional or master/graduate courses refers to courselevel = 'Level_500';
Question: How many professional or master/graduate courses are there?
SQL: SELECT count(*) FROM course WHERE courselevel = 'Level_500'
Database: computer_student
Note: non-faculty members refers to hasposition = 0; are not undergoing the phase of qualifications refers to inphase = 0;
Question: How many non-faculty members are not undergoing the phase of qualifications?
SQL: SELECT count(*) FROM person WHERE hasposition = 0 AND inphase = 0
Database: computer_student
Note: professor refers to taughtby.p_id; least amount of courses refers to min(count(course_id));
Question: Which professor taught the least amount of courses?
SQL: SELECT p_id FROM taughtby GROUP BY p_id ORDER BY count(course_id) ASC LIMIT 1
Database: computer_student
Note: Advisor 5 refers to p_id_dummy = 5; are in the 5th year refers to yearsinprogram = 'Year_5';
Question: Among the students being advised by Advisor 5, how many students are in the 5th year?
SQL: SELECT count(*) FROM advisedby INNER JOIN person ON advisedby.p_id = person.p_id WHERE advisedby.p_id_dummy = 5 AND person.student = 1 AND person.yearsinprogram = 'Year_5'
Database: computer_student
Note: 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';
Question: Which professor teaches the highest number of professional or master/graduate courses?
SQL: SELECT taughtby.p_id FROM course INNER JOIN taughtby ON course.course_id = taughtby.course_id WHERE course.courselevel = 'Level_500' GROUP BY taughtby.p_id ORDER BY count(taughtby.course_id) DESC LIMIT 1
Database: computer_student
Note: faculty affiliated professor refers to professor = 1 and hasposition = 'Faculty_aff'; professional or master/undergraduate courses refers to courselevel = 'Level_500';
Question: Among the faculty affiliated professor, how many professors teaches professional or master/undergraduate courses?
SQL: SELECT count(*) FROM person INNER JOIN taughtby ON person.p_id = taughtby.p_id INNER JOIN course ON course.course_id = taughtby.course_id WHERE person.hasposition = 'Faculty_aff' AND person.professor = 1 AND course.courselevel = 'Level_500'
Database: computer_student
Note: professors refers to course.p_id; highest number of professional or master/undergraduate courses refers to max(count(course.course_id)) where courselevel = 'Level_500';
Question: Who are the top 5 professors who teaches the highest number of professional or master/undergraduate courses?
SQL: SELECT taughtby.p_id FROM course INNER JOIN taughtby ON course.course_id = taughtby.course_id WHERE course.courselevel = 'Level_500' GROUP BY taughtby.p_id ORDER BY count(taughtby.p_id) DESC LIMIT 5
Database: computer_student
Note: advisors refers to p_id_dummy; students in 1st year refers to student = 1 and yearsinprogram = 'Year_1';
Question: How many advisors are in charge of advising all the students in 1st year?
SQL: SELECT count(advisedby.p_id_dummy) FROM advisedby INNER JOIN person ON advisedby.p_id = person.p_id WHERE person.yearsinprogram = 'Year_1' AND person.student = 1
Database: computer_student
Note: professors refers to taughtby.p_id; high-level or harder undergraduate courses  refers to courselevel = 'Level_400' ; no more than two refers to count(taughtby.course_id) <= 2;
Question: How many professors teaches no more than two high-level or harder undergraduate courses?
SQL: SELECT count(*) FROM ( SELECT count(taughtby.p_id) FROM course INNER JOIN taughtby ON course.course_id = taughtby.course_id WHERE course.courselevel = 'Level_400' GROUP BY taughtby.p_id HAVING count(DISTINCT course.course_id) <= 2 )
Database: computer_student
Note: faculty employee professors refers to hasposition = 'Faculty_eme' and professor = 1; high-level or harder undergraduate courses refers to courselevel = 'Level_400'; professors unique identifying number refers to person.p_id;
Question: Between the faculty employee professors, how many teaches high-level or harder undergraduate courses? Indicate each of the professors unique identifying number.
SQL: SELECT count(*) FROM person INNER JOIN taughtby ON person.p_id = taughtby.p_id INNER JOIN course ON course.course_id = taughtby.course_id WHERE person.hasposition = 'Faculty_eme' AND person.professor = 1 AND course.courselevel = 'Level_400'
Database: computer_student
Note: position in the faculty refers to hasposition; professor refers to professor = 1; teaches the highest number of courses refers to max(count(taughtby.course_id));
Question: What is the position in the faculty of the professor who teaches the highest number of courses?
SQL: SELECT person.hasposition FROM person INNER JOIN taughtby ON person.p_id = taughtby.p_id WHERE person.professor = 1 GROUP BY person.p_id ORDER BY count(taughtby.course_id) DESC LIMIT 1
Database: computer_student
Note: students refers to student = 1; more than 2 advisors refers to count(p_id_dummy) > 2;
Question: What year in the program do the students with more than 2 advisors are in?
SQL: SELECT person.yearsinprogram FROM advisedby INNER JOIN person ON advisedby.p_id = person.p_id WHERE person.student = 1 GROUP BY person.p_id HAVING count(person.p_id) > 2
Database: computer_student
Note: professors refers to taughtby.p_id; basic or medium undergraduate courses refers to couresLevel = 'Level_300';
Question: How many professors teaches basic or medium undergraduate courses?
SQL: SELECT count(*) FROM course INNER JOIN taughtby ON course.course_id = taughtby.course_id WHERE course.courselevel = 'Level_300'
Database: computer_student
Note: students refers to student = 1; students' year in the program do the advisors advise the majority of refers to max(count(yearsinprogram));
Question: Among the students being advised by advisors, which students' year in the program do the advisors advise the majority of?
SQL: SELECT person.yearsinprogram FROM advisedby INNER JOIN person ON advisedby.p_id = person.p_id WHERE person.student = 1 GROUP BY person.yearsinprogram ORDER BY count(advisedby.p_id_dummy) DESC LIMIT 1
Database: computer_student
Note: students refers to student = 1 and ; undergoing the phase of pre-qualification refers to inphase = 'Pre-Quals'; have advisors refers to advisedby.p_id;
Question: How many students that are undergoing the pre-phase of qualification have advisors?
SQL: SELECT count(advisedby.p_id_dummy) FROM advisedby INNER JOIN person ON advisedby.p_id = person.p_id WHERE person.inphase = 'Pre_Quals' AND person.student = 1
Database: computer_student
Note: professional or master/undergraduate courses refers to courselevel = 'Level_500'; average number = divide(count(taughtby.course_id), count(taughtby.p_id));
Question: What is the average number of professional or master/undergraduate courses being taught by each professor?
SQL: SELECT cast(count(course.course_id) AS REAL) / count(DISTINCT taughtby.p_id) FROM course INNER JOIN taughtby ON course.course_id = taughtby.course_id WHERE course.courselevel = 'Level_500'
Database: computer_student
Note: courses refers to taughtby.course_id; more than 4 people refers to count(taughtby.p_id) > 4;
Question: How many courses were taught by more than 4 people?
SQL: SELECT count(*) FROM ( SELECT count(course_id) FROM taughtby GROUP BY course_id HAVING count(course_id) > 4 )
Database: computer_student
Note: professional courses refers to courselevel = 'Level_500'; course id refers to course.course_id;
Question: What is the total of professional courses available at the university? List out all the course id.
SQL: SELECT count(course_id) FROM course WHERE courselevel = 'Level_500'
Database: computer_student
Note: year 1 and year 2 students refers to yearsinprogram = 'Year_1' and yearsinprogram = 'Year_2' and student = 1;
Question: What is the sum of year 1 and year 2 students?
SQL: SELECT count(*) FROM person WHERE yearsinprogram = 'Year_1' OR yearsinprogram = 'Year_2'
Database: computer_student
Note: professor refers to professor = 1;  member of faculty refers to hasposition <> 0;
Question: How many courses were taught by a professor who is currently the member of faculty?
SQL: SELECT count(*) FROM person INNER JOIN taughtby ON person.p_id = taughtby.p_id WHERE person.professor = 1 AND person.hasposition <> 0
Database: computer_student
Note: professor refers to taughtby.p_id; most courses refers to max(taughtby.p_id); position refers to hasposition;
Question: Which professor taught the most courses and what is the position of this person in the university?
SQL: SELECT person.p_id, person.hasposition FROM person INNER JOIN taughtby ON person.p_id = taughtby.p_id GROUP BY person.p_id ORDER BY count(taughtby.course_id) DESC LIMIT 1
Database: computer_student
Note: courses refers to taughtby.course_id; professor refers to professor = 1; is not a faculty member refers to hasposition = 0;
Question: Which courses were taught by a professor who is not a faculty member?
SQL: SELECT DISTINCT taughtby.course_id FROM person INNER JOIN taughtby ON person.p_id = taughtby.p_id WHERE person.professor = 1 AND person.hasposition = 0
Database: computer_student
Note: member of the faculty refers to hasposition <> 0, most courses refers to max(count(course.course_id));
Question: Which member of the faculty are teaching the most courses and what is his/her general course level?
SQL: SELECT person.p_id, course.courselevel FROM person INNER JOIN taughtby ON person.p_id = taughtby.p_id INNER JOIN course ON course.course_id = taughtby.course_id GROUP BY person.p_id ORDER BY count(taughtby.course_id) DESC LIMIT 1
Database: talkingdata
Note: oldest user refers to MAX(age);
Question: What is the device id of the oldest user?
SQL: SELECT device_id FROM gender_age WHERE age = ( SELECT max(age) FROM gender_age )
Database: talkingdata
Note: coordinate 97,40 refers to longitude = 97 AND latitude = 40;
Question: How many events were held at coordinate 97,40?
SQL: SELECT count(event_id) FROM `events` WHERE latitude = 40 AND longitude = 97
Database: talkingdata
Note: male refers to gender = 'M'; age group refers to group; `group` = 'm32-38';
Question: How many male users are in the age group of M32-38?
SQL: SELECT count(gender) FROM gender_age WHERE gender = 'M' AND `group` = 'M32-38'
Database: talkingdata
Note: female refers to gender = 'F'; over the age of 50 refers to age > 50;
Question: How many female users over the age of 50 are there?
SQL: SELECT count(gender) FROM gender_age WHERE age > 50 AND gender = 'F'
Database: talkingdata
Note: active users refers to is_active = 1;
Question: How many active users were there in the event id 2?
SQL: SELECT count(is_active) FROM app_events WHERE event_id = 2 AND is_active = 1
Database: talkingdata
Note: youngest user refers to MIN(age);
Question: What is the gender of the youngest user?
SQL: SELECT gender FROM gender_age WHERE age = ( SELECT min(age) FROM gender_age )
Database: talkingdata
Note: most users belong to refers to MAX(COUNT(app_id)); name of category refers to category;
Question: What is the name of the category which most users belong to?
SQL: SELECT t.category FROM ( SELECT label_categories.category, count(app_labels.app_id) AS num FROM app_labels INNER JOIN label_categories ON label_categories.label_id = app_labels.label_id GROUP BY app_labels.app_id, label_categories.category ) AS t ORDER BY t.num DESC LIMIT 1
Database: talkingdata
Note: model of the device refers to device_model; oldest user refers to MAX(age);
Question: What is the model of the oldest user's device?
SQL: SELECT phone_brand_device_model2.device_model FROM phone_brand_device_model2 INNER JOIN gender_age ON gender_age.device_id = phone_brand_device_model2.device_id ORDER BY gender_age.age DESC LIMIT 1
Database: talkingdata
Question: How many users are there in the Home Decoration category?
SQL: SELECT count(app_labels.app_id) FROM app_labels INNER JOIN label_categories ON label_categories.label_id = app_labels.label_id WHERE label_categories.category = 'Home Decoration'
Database: talkingdata
Note: male refers to gender = 'M'; active refers to is_active = 1; on 5/1/2016 refers to timestamp LIKE '2016-05-01%';
Question: How many male users are active in the events held on 5/1/2016?
SQL: SELECT count(gender_age.gender) FROM app_events INNER JOIN events_relevant ON events_relevant.event_id = app_events.event_id INNER JOIN gender_age ON gender_age.device_id = events_relevant.device_id WHERE app_events.is_active = 1 AND gender_age.gender = 'M' AND events_relevant.timestamp LIKE '2016-05-01%'
Database: talkingdata
Note: female refers to gender = 'F'; ZenFone 5 refers to device_model = 'ZenFone 5';
Question: How many female users use ZenFone 5 devices?
SQL: SELECT count(gender_age.gender) FROM gender_age INNER JOIN phone_brand_device_model2 ON phone_brand_device_model2.device_id = gender_age.device_id WHERE gender_age.gender = 'F' AND phone_brand_device_model2.device_model = 'ZenFone 5'
Database: talkingdata
Note: oldest user refers to MAX(age); active user refers to is_active = 1; on 5/6/2016 refers to timestamp LIKE '2016-05-06%'; coordinates 121, 31 refers to longitude = 121 AND latitude = 31;
Question: What is the age of the oldest active user that participated in the event held on 5/6/2016 at coordinates 121, 31?
SQL: SELECT gender_age.age FROM app_events INNER JOIN events_relevant ON app_events.event_id = events_relevant.event_id INNER JOIN gender_age ON events_relevant.device_id = gender_age.device_id WHERE app_events.is_active = 1 AND events_relevant.longitude = 121 AND events_relevant.latitude = 31 AND substr(events_relevant.timestamp, 1, 10) = '2016-05-06' ORDER BY gender_age.age DESC LIMIT 1
Database: talkingdata
Note: most common device model refers to MAX(COUNT(device_id)); female refers to gender = 'F'; between the ages 27 to 28 refers to group = 'f27-28';
Question: What is the most common device model among female users between the ages 27 to 28?
SQL: SELECT phone_brand_device_model2.device_model FROM gender_age INNER JOIN phone_brand_device_model2 ON gender_age.device_id = phone_brand_device_model2.device_id WHERE gender_age.`group` = 'F27-28' AND gender_age.gender = 'F' ORDER BY phone_brand_device_model2.device_id DESC LIMIT 1
Database: talkingdata
Note: oldest event refers to MIN(timestamp);
Question: What are the categories of the top 2 oldest events?
SQL: SELECT label_categories.category FROM events_relevant INNER JOIN app_events_relevant ON events_relevant.event_id = app_events_relevant.event_id INNER JOIN app_labels ON app_labels.app_id = app_events_relevant.app_id INNER JOIN label_categories ON app_labels.label_id = label_categories.label_id ORDER BY events_relevant.timestamp LIMIT 2
Database: talkingdata
Note: majority of Vivo phone users refers to MAX(COUNT(phone_brand = 'vivo'));
Question: What is the gender of the majority of Vivo phone users?
SQL: SELECT t.gender FROM ( SELECT gender_age.gender, count(gender_age.gender) AS num FROM phone_brand_device_model2 INNER JOIN gender_age ON gender_age.device_id = phone_brand_device_model2.device_id WHERE phone_brand_device_model2.phone_brand = 'vivo' GROUP BY gender_age.gender ) AS t ORDER BY t.num DESC LIMIT 1
Database: talkingdata
Note: highest number of users refers to MAX(COUNT(app_id));
Question: Which category has the highest number of users?
SQL: SELECT t.category FROM ( SELECT label_categories.category, count(app_labels.app_id) AS num FROM app_labels INNER JOIN label_categories ON label_categories.label_id = app_labels.label_id GROUP BY app_labels.app_id, label_categories.category ) AS t ORDER BY t.num DESC LIMIT 1
Database: talkingdata
Question: How many users belong to the MOBA category?
SQL: SELECT count(app_labels.app_id) FROM label_categories INNER JOIN app_labels ON app_labels.label_id = label_categories.label_id WHERE label_categories.category = 'MOBA'
Database: talkingdata
Note: percentage = DIVIDE(MULTIPLY(CONCAT(COUNT(device_id WHERE phone_brand = 'OPPO' AND gender = 'F'), 100), COUNT(device_id)), '%') AS 'the percentage of female OPPO users'; DIVIDE(MULTIPLY(CONCAT(COUNT(device_id WHERE phone_brand = 'OPPO' AND gender = 'M'), 100), COUNT(device_id)), '%') AS 'the percentage of male OPPO users';
Question: What is the percentage of female OPPO users against the male OPPO users?
SQL: SELECT sum(iif(gender_age.gender = 'F', 1, 0)) * 100 / count(gender_age.device_id) AS perfemale , sum(iif(gender_age.gender = 'M', 1, 0)) * 100 / count(gender_age.device_id) AS permale FROM phone_brand_device_model2 INNER JOIN gender_age ON gender_age.device_id = phone_brand_device_model2.device_id WHERE phone_brand_device_model2.phone_brand = 'OPPO'
Database: talkingdata
Note: location = longitude, latitude; on 8th May, 2016 refers to `timestamp` LIKE '2016-05-08%';
Question: What were the locations of the events on 8th May, 2016?
SQL: SELECT longitude, latitude FROM `events` WHERE substr(`timestamp`, 1, 10) = '2016-05-08'
Database: talkingdata
Note: app user IDs refers to app_id; is_installed = 1 means the app status is installed; is_installed = 0 means the app status is not installed;
Question: List the app users IDs and installed status for the event ID of 844.
SQL: SELECT app_id , iif(is_installed = 1, 'YES', 'NO') AS status FROM app_events WHERE event_id = 844
Database: talkingdata
Note: on 30th April, 2016 refers to `timestamp` LIKE '2016-04-30%';
Question: How many events were there on 30th April, 2016?
SQL: SELECT count(event_id) FROM EVENTS WHERE substr(`timestamp`, 1, 10) = '2016-04-30'
Database: talkingdata
Note: Vivo Xplay3S model refers to phone_brand = 'vivo' AND device_model = 'Xplay3S';
Question: How many users used Vivo Xplay3S model?
SQL: SELECT count(device_id) FROM phone_brand_device_model2 WHERE device_model = 'Xplay3S' AND phone_brand = 'vivo'
Database: talkingdata
Note: ratio = DIVIDE(COUNT(device_id WHERE gender = 'M' AND `group` = 'm27-28'), COUNT(device_id WHERE gender = 'F' AND `group` = 'f27-28')); 27-28 age group refers to `group` = 'f27-28';
Question: What is the ratio of male and female users in 27-28 age group?
SQL: SELECT sum(iif(gender = 'M' AND `group` = 'M27-28', 1, 0)) / sum(iif(gender = 'F' AND `group` = 'F27-28', 1, 0)) AS r FROM gender_age
Database: talkingdata
Question: What are the labels' IDs of online shopping and online malls categories?
SQL: SELECT label_id FROM label_categories WHERE category IN ('online shopping', 'online malls')
Database: talkingdata
Note: models refers to device_model; on 5th May, 2016 refers to timestamp LIKE '2016-05-05%'; coordinates of (112,44) refers to longitude = 112 AND latitude = 44;
Question: Describe the phone brands and models of the users who participated in events on 5th May, 2016 at the coordinates of (112,44).
SQL: SELECT DISTINCT phone_brand_device_model2.phone_brand, phone_brand_device_model2.device_model FROM EVENTS INNER JOIN phone_brand_device_model2 ON phone_brand_device_model2.device_id = EVENTS.device_id WHERE EVENTS.timestamp LIKE '2016-05-05%' AND EVENTS.longitude = 112 AND EVENTS.latitude = 44
Database: talkingdata
Note: app user IDs refers to app_id; time refers to timestamp;
Question: Provide the app users IDs and time for the event ID of 82.
SQL: SELECT app_events.app_id, EVENTS.timestamp FROM app_events INNER JOIN EVENTS ON EVENTS.event_id = app_events.event_id WHERE EVENTS.event_id = 82
Database: talkingdata
Question: Describe the device user gender and age of the event ID of 15251.
SQL: SELECT gender_age.gender, gender_age.age FROM gender_age INNER JOIN EVENTS ON EVENTS.device_id = gender_age.device_id WHERE EVENTS.event_id = 15251
Database: talkingdata
Note: 88-years-old refers to age = 88; male refers to gender = 'M'; on 4th May, 2016 refers to timestamp LIKE '2016-05-04%';
Question: How many events did the 88-years-old male users participate on 4th May,2016?
SQL: SELECT count(EVENTS.event_id) FROM gender_age INNER JOIN EVENTS ON EVENTS.device_id = gender_age.device_id WHERE gender_age.gender = 'M' AND substr(`timestamp`, 1, 10) = '2016-05-04' AND gender_age.age = 88