birdsql/bird_sql_dev_20251106 huggingface dataset:
Database: california_schools
Question: For the school with the highest free meal rate in Alameda County, what are its characteristics including whether it's a charter school, what grades it serves, its SAT performance level, and how much its free meal rate deviates from the county average?
Evidence: Free meal rate = Free Meal Count (K-12) / Enrollment (K-12). SAT performance levels are categorized as: Below Average (total score < 1200), Average (1200-1500), Above Average (> 1500), or No SAT Data if unavailable.
SQL:
WITH CountyStats AS (
    SELECT 
        f.`County Name`,
        f.`School Name`,
        f.`Free Meal Count (K-12)`,
        f.`Enrollment (K-12)`,
        CAST(f.`Free Meal Count (K-12)` AS REAL) / f.`Enrollment (K-12)` AS FreeRate,
        s.sname,
        s.AvgScrRead,
        s.AvgScrMath,
        s.AvgScrWrite,
        (s.AvgScrRead + s.AvgScrMath + s.AvgScrWrite) AS TotalSATScore,
        sc.Charter,
        sc.GSserved,
        RANK() OVER (PARTITION BY f.`County Name` ORDER BY CAST(f.`Free Meal Count (K-12)` AS REAL) / f.`Enrollment (K-12)` DESC) AS CountyRank
    FROM frpm f
    LEFT JOIN schools sc ON f.CDSCode = sc.CDSCode
    LEFT JOIN satscores s ON f.CDSCode = s.cds
    WHERE f.`Enrollment (K-12)` > 0 
    AND f.`County Name` = 'Alameda'
)
SELECT 
    cs.`County Name` AS County,
    cs.`School Name`,
    cs.FreeRate AS HighestFreeRate,
    cs.`Free Meal Count (K-12)` AS FreeMealCount,
    cs.`Enrollment (K-12)` AS TotalEnrollment,
    CASE 
        WHEN cs.Charter = 1 THEN 'Yes'
        WHEN cs.Charter = 0 THEN 'No'
        ELSE 'Unknown'
    END AS IsCharterSchool,
    cs.GSserved AS GradesServed,
    CASE
        WHEN cs.TotalSATScore IS NULL THEN 'No SAT Data'
        WHEN cs.TotalSATScore < 1200 THEN 'Below Average'
        WHEN cs.TotalSATScore BETWEEN 1200 AND 1500 THEN 'Average'
        ELSE 'Above Average'
    END AS SATPerformance,
    (SELECT AVG(CAST(f2.`Free Meal Count (K-12)` AS REAL) / f2.`Enrollment (K-12)`)
     FROM frpm f2
     WHERE f2.`County Name` = 'Alameda' AND f2.`Enrollment (K-12)` > 0) AS CountyAverageFreeRate,
    cs.FreeRate - (SELECT AVG(CAST(f2.`Free Meal Count (K-12)` AS REAL) / f2.`Enrollment (K-12)`)
                  FROM frpm f2
                  WHERE f2.`County Name` = 'Alameda' AND f2.`Enrollment (K-12)` > 0) AS DeviationFromCountyAverage
FROM CountyStats cs
WHERE cs.CountyRank = 1
ORDER BY cs.FreeRate DESC
LIMIT 1;
Database: california_schools
Question: Please list the lowest three eligible free rates for students aged 5-17 in continuation schools.
Evidence: Eligible free rates for students aged 5-17 = `Free Meal Count (Ages 5-17)` / `Enrollment (Ages 5-17)`
SQL:
SELECT `Free Meal Count (Ages 5-17)` / `Enrollment (Ages 5-17)` FROM frpm WHERE `Educational Option Type` = 'Continuation School' AND `Free Meal Count (Ages 5-17)` / `Enrollment (Ages 5-17)` IS NOT NULL ORDER BY `Free Meal Count (Ages 5-17)` / `Enrollment (Ages 5-17)` ASC LIMIT 3
Database: california_schools
Question: For charter schools in Fresno County Office of Education, provide their location details, enrollment information, FRPM eligibility rates, SAT performance metrics, and rankings. Include the year each school opened and whether it's currently active or closed, categorizing schools by their FRPM percentage levels.
Evidence: Charter schools refers to `Charter School (Y/N)` = 1; FRPM refers to Free or Reduced Price Meal program eligibility; Schools with FRPM > 75% are High FRPM, 50-75% are Medium FRPM, and below 50% are Low FRPM
SQL:
WITH CharterSchoolInfo AS (
    SELECT 
        T1.CDSCode,
        T1.`School Name` AS CharterSchoolName,
        T1.`District Name`,
        T1.`Charter School Number`,
        T1.`Charter Funding Type`,
        T1.`Enrollment (K-12)` AS Enrollment,
        T1.`FRPM Count (K-12)` AS FRPMCount,
        T1.`Percent (%) Eligible FRPM (K-12)` AS PercentFRPM,
        T2.Zip,
        T2.City,
        T2.Street,
        T2.OpenDate,
        CASE 
            WHEN T2.ClosedDate IS NULL THEN 'Active'
            ELSE 'Closed'
        END AS CurrentStatus,
        CASE
            WHEN T1.`Percent (%) Eligible FRPM (K-12)` > 0.75 THEN 'High FRPM'
            WHEN T1.`Percent (%) Eligible FRPM (K-12)` > 0.50 THEN 'Medium FRPM'
            ELSE 'Low FRPM'
        END AS FRPMCategory
    FROM frpm AS T1 
    INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode
    WHERE T1.`District Name` = 'Fresno County Office of Education' 
    AND T1.`Charter School (Y/N)` = 1
),
SATPerformance AS (
    SELECT 
        cds,
        sname,
        NumTstTakr,
        AvgScrRead,
        AvgScrMath,
        AvgScrWrite,
        (AvgScrRead + AvgScrMath + AvgScrWrite) AS TotalSATScore,
        CAST(NumGE1500 AS FLOAT) / NULLIF(NumTstTakr, 0) AS PercentageAbove1500
    FROM satscores
    WHERE rtype = 'S'
)

SELECT 
    c.Zip,
    c.City,
    c.CharterSchoolName,
    c.`Charter Funding Type`,
    c.Enrollment,
    c.PercentFRPM,
    c.FRPMCategory,
    STRFTIME('%Y', c.OpenDate) AS YearOpened,
    c.CurrentStatus,
    s.NumTstTakr AS SATTestTakers,
    s.TotalSATScore,
    s.PercentageAbove1500,
    RANK() OVER (ORDER BY s.TotalSATScore DESC NULLS LAST) AS SATRanking,
    RANK() OVER (ORDER BY c.Enrollment DESC) AS EnrollmentRanking
FROM CharterSchoolInfo c
LEFT JOIN SATPerformance s ON c.CDSCode = s.cds
ORDER BY 
    CASE WHEN s.TotalSATScore IS NULL THEN 1 ELSE 0 END,
    s.TotalSATScore DESC,
    c.Enrollment DESC;
Database: california_schools
Question: For the non-charter school with more than 100 students that has the highest number of FRPM-eligible K-12 students, provide its name, location details, unabbreviated mailing address, website, enrollment statistics, SAT performance metrics, and determine whether it performs unexpectedly well or poorly given its FRPM rate.
Evidence: Non-charter schools have Charter School (Y/N) = 0. FRPM stands for Free or Reduced Price Meal program. High-performing despite high FRPM means FRPM percentage > 70% and percentage of students scoring >= 1500 on SAT > 20%. Low-performing despite low FRPM means FRPM percentage < 30% and percentage of students scoring >= 1500 on SAT < 10%.
SQL:
WITH SchoolRanking AS (
    SELECT 
        T1.CDSCode,
        T1.`School Name`,
        T1.`FRPM Count (K-12)`,
        T1.`Enrollment (K-12)`,
        T1.`Percent (%) Eligible FRPM (K-12)`,
        RANK() OVER (ORDER BY T1.`FRPM Count (K-12)` DESC) AS frpm_rank,
        RANK() OVER (ORDER BY T1.`Percent (%) Eligible FRPM (K-12)` DESC) AS frpm_percent_rank
    FROM 
        frpm AS T1
    WHERE 
        T1.`Enrollment (K-12)` > 100 -- Only consider schools with significant enrollment
        AND T1.`Charter School (Y/N)` = 0 -- Non-charter schools only
),
SATPerformance AS (
    SELECT 
        s.cds,
        s.sname,
        s.NumTstTakr,
        s.AvgScrRead + s.AvgScrMath + s.AvgScrWrite AS TotalSATScore,
        CASE 
            WHEN s.AvgScrRead + s.AvgScrMath + s.AvgScrWrite >= 1500 THEN 'High'
            WHEN s.AvgScrRead + s.AvgScrMath + s.AvgScrWrite >= 1200 THEN 'Medium'
            ELSE 'Low'
        END AS PerformanceCategory,
        CAST(s.NumGE1500 AS FLOAT) / NULLIF(s.NumTstTakr, 0) * 100 AS PercentHighScorers
    FROM 
        satscores s
    WHERE 
        s.NumTstTakr > 10 -- Only schools with enough test takers
)
SELECT 
    sr.`School Name` AS SchoolName,
    sch.County,
    sch.City,
    sch.MailStreet AS UnabbreviatedMailingAddress,
    sch.Website,
    sr.`Enrollment (K-12)` AS Enrollment,
    sr.`FRPM Count (K-12)` AS FRPMCount,
    sr.`Percent (%) Eligible FRPM (K-12)` AS FRPMPercentage,
    sp.TotalSATScore,
    sp.PerformanceCategory,
    sp.PercentHighScorers,
    CASE 
        WHEN sp.PercentHighScorers IS NULL THEN 'No SAT data'
        WHEN sr.`Percent (%) Eligible FRPM (K-12)` > 0.7 AND sp.PercentHighScorers > 20 THEN 'High-performing despite high FRPM'
        WHEN sr.`Percent (%) Eligible FRPM (K-12)` < 0.3 AND sp.PercentHighScorers < 10 THEN 'Low-performing despite low FRPM'
        ELSE 'Expected performance'
    END AS PerformanceClassification,
    sch.OpenDate,
    CASE
        WHEN sch.ClosedDate IS NOT NULL THEN 'Closed'
        ELSE 'Active'
    END AS SchoolStatus
FROM 
    SchoolRanking sr
JOIN 
    schools sch ON sr.CDSCode = sch.CDSCode
LEFT JOIN 
    SATPerformance sp ON sr.CDSCode = sp.cds
WHERE 
    sr.frpm_rank = 1 -- School with highest FRPM count
ORDER BY 
    sr.`FRPM Count (K-12)` DESC
LIMIT 1;
Database: california_schools
Question: Please list the phone numbers of the direct charter-funded schools that are opened after 2000/1/1.
Evidence: Charter schools refers to `Charter School (Y/N)` = 1 in the frpm
SQL:
SELECT T2.Phone FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T1.`Charter Funding Type` = 'Directly funded' AND T1.`Charter School (Y/N)` = 1 AND T2.OpenDate > '2000-01-01'
Database: california_schools
Question: What are the details of fully virtual schools that have an average SAT Math score above 400, including their SAT performance rankings, enrollment, and poverty levels, ordered by their total SAT scores?
Evidence: Fully virtual refers to Virtual = 'F'; poverty level is categorized based on the percentage of students eligible for free or reduced price meals (FRPM)
SQL:
WITH VirtualSchools AS (
    SELECT 
        s.CDSCode,
        s.School,
        s.Virtual,
        s.Charter,
        s.City,
        CASE 
            WHEN s.Virtual = 'F' THEN 'Fully Virtual'
            WHEN s.Virtual = 'P' THEN 'Partially Virtual'
            WHEN s.Virtual = 'N' THEN 'Not Virtual'
            ELSE 'Unknown'
        END AS VirtualStatus
    FROM schools s
    WHERE s.Virtual = 'F'
),
SATPerformance AS (
    SELECT 
        sat.cds,
        sat.sname,
        sat.AvgScrMath,
        sat.AvgScrRead,
        sat.AvgScrWrite,
        (sat.AvgScrMath + sat.AvgScrRead + sat.AvgScrWrite) AS TotalScore,
        RANK() OVER (ORDER BY sat.AvgScrMath DESC) AS MathRank,
        RANK() OVER (ORDER BY (sat.AvgScrMath + sat.AvgScrRead + sat.AvgScrWrite) DESC) AS TotalScoreRank
    FROM satscores sat
    WHERE sat.AvgScrMath > 400
),
SchoolEnrollmentData AS (
    SELECT 
        f.CDSCode,
        f.`School Name`,
        f.`Enrollment (K-12)`,
        f.`FRPM Count (K-12)`,
        f.`Percent (%) Eligible FRPM (K-12)`,
        CASE 
            WHEN f.`Percent (%) Eligible FRPM (K-12)` >= 0.75 THEN 'High Poverty'
            WHEN f.`Percent (%) Eligible FRPM (K-12)` >= 0.50 THEN 'Medium Poverty'
            WHEN f.`Percent (%) Eligible FRPM (K-12)` >= 0.25 THEN 'Low Poverty'
            ELSE 'Very Low Poverty'
        END AS PovertyLevel
    FROM frpm f
)
SELECT 
    vs.School AS SchoolName,
    vs.City,
    vs.VirtualStatus,
    CASE WHEN vs.Charter = 1 THEN 'Charter School' ELSE 'Regular School' END AS SchoolType,
    sp.AvgScrMath AS MathScore,
    sp.AvgScrRead AS ReadingScore,
    sp.AvgScrWrite AS WritingScore,
    sp.TotalScore,
    sp.MathRank,
    sp.TotalScoreRank,
    sed.`Enrollment (K-12)` AS Enrollment,
    sed.PovertyLevel,
    ROUND(sed.`Percent (%) Eligible FRPM (K-12)` * 100, 1) || '%' AS FRPMPercentage
FROM VirtualSchools vs
JOIN SATPerformance sp ON vs.CDSCode = sp.cds
LEFT JOIN SchoolEnrollmentData sed ON vs.CDSCode = sed.CDSCode
ORDER BY sp.TotalScore DESC, sed.`Enrollment (K-12)` DESC;
Database: california_schools
Question: For magnet schools with over 500 SAT test takers, provide a comprehensive performance analysis including their SAT scores, rankings, poverty levels, and performance categories, sorted by total average SAT scores.
Evidence: Magnet schools refers to Magnet = 1; Total average SAT score is the sum of average reading, math, and writing scores; Poverty level is categorized based on the percentage eligible for free or reduced-price meals (FRPM).
SQL:
WITH SchoolMetrics AS (
    SELECT 
        s.CDSCode,
        s.School,
        s.Magnet,
        s.SOCType AS SchoolType,
        s.EdOpsName AS EducationalOption,
        sat.NumTstTakr,
        sat.AvgScrRead,
        sat.AvgScrMath,
        sat.AvgScrWrite,
        sat.NumGE1500,
        CAST(sat.NumGE1500 AS FLOAT) / NULLIF(sat.NumTstTakr, 0) * 100 AS PercentHighScorers,
        (sat.AvgScrRead + sat.AvgScrMath + sat.AvgScrWrite) AS TotalAvgScore,
        f.`Enrollment (K-12)` AS Enrollment,
        f.`FRPM Count (K-12)` AS FRPMCount,
        f.`Percent (%) Eligible FRPM (K-12)` AS FRPMPercent,
        RANK() OVER(ORDER BY (sat.AvgScrRead + sat.AvgScrMath + sat.AvgScrWrite) DESC) AS ScoreRank,
        DENSE_RANK() OVER(PARTITION BY s.County ORDER BY (sat.AvgScrRead + sat.AvgScrMath + sat.AvgScrWrite) DESC) AS CountyRank
    FROM satscores sat
    INNER JOIN schools s ON sat.cds = s.CDSCode
    LEFT JOIN frpm f ON s.CDSCode = f.CDSCode
    WHERE sat.NumTstTakr > 500
)

SELECT 
    sm.School,
    sm.SchoolType,
    sm.EducationalOption,
    sm.NumTstTakr AS TestTakers,
    sm.TotalAvgScore,
    sm.AvgScrRead AS ReadingScore,
    sm.AvgScrMath AS MathScore,
    sm.AvgScrWrite AS WritingScore,
    sm.PercentHighScorers,
    sm.Enrollment,
    sm.FRPMPercent AS FreeReducedMealPercentage,
    sm.ScoreRank AS StateRank,
    sm.CountyRank,
    CASE 
        WHEN sm.FRPMPercent > 0.75 THEN 'High Poverty'
        WHEN sm.FRPMPercent > 0.50 THEN 'Moderate Poverty'
        WHEN sm.FRPMPercent > 0.25 THEN 'Low Poverty'
        ELSE 'Very Low Poverty'
    END AS PovertyLevel,
    CASE 
        WHEN sm.TotalAvgScore > 1800 THEN 'Excellent'
        WHEN sm.TotalAvgScore > 1500 THEN 'Good'
        WHEN sm.TotalAvgScore > 1200 THEN 'Average'
        ELSE 'Below Average'
    END AS PerformanceCategory
FROM SchoolMetrics sm
WHERE sm.Magnet = 1
ORDER BY sm.TotalAvgScore DESC, sm.PercentHighScorers DESC
Database: california_schools
Question: What is the phone number of the school that has the highest number of test takers with an SAT score of over 1500?
SQL:
SELECT T2.Phone FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode ORDER BY T1.NumGE1500 DESC LIMIT 1
Database: california_schools
Question: For the top 10 schools with the highest number of students eligible for free or reduced price meals, provide detailed information including their location, type, FRPM statistics, and SAT performance metrics.
Evidence: FRPM refers to Free or Reduced Price Meal program. FRPM Count (K-12) represents the number of students eligible for the program.
SQL:
WITH SchoolsWithHighFRPM AS (
    SELECT 
        f.CDSCode,
        f.`School Name`,
        f.`FRPM Count (K-12)`,
        f.`Enrollment (K-12)`,
        f.`Percent (%) Eligible FRPM (K-12)`,
        RANK() OVER (ORDER BY f.`FRPM Count (K-12)` DESC) as frpm_rank
    FROM frpm f
    WHERE f.`FRPM Count (K-12)` IS NOT NULL
),
SchoolDetails AS (
    SELECT 
        s.CDSCode,
        s.School,
        s.County,
        s.District,
        s.Charter,
        s.GSoffered,
        CASE 
            WHEN s.Charter = 1 THEN 'Charter School'
            ELSE 'Non-Charter School'
        END as school_type,
        CASE
            WHEN s.GSoffered LIKE '%K%' AND s.GSoffered LIKE '%12%' THEN 'K-12'
            WHEN s.GSoffered LIKE '%9%' AND s.GSoffered LIKE '%12%' THEN 'High School'
            WHEN s.GSoffered LIKE '%6%' AND s.GSoffered LIKE '%8%' THEN 'Middle School'
            WHEN s.GSoffered LIKE '%K%' AND s.GSoffered LIKE '%5%' THEN 'Elementary School'
            ELSE 'Other'
        END as grade_level
    FROM schools s
),
SATDetails AS (
    SELECT 
        sat.cds,
        sat.NumTstTakr,
        sat.AvgScrRead,
        sat.AvgScrMath,
        sat.AvgScrWrite,
        sat.NumGE1500,
        (sat.AvgScrRead + sat.AvgScrMath + sat.AvgScrWrite) as total_avg_score,
        CASE 
            WHEN sat.enroll12 > 0 THEN ROUND((CAST(sat.NumTstTakr AS REAL) / sat.enroll12) * 100, 2)
            ELSE NULL
        END as percent_taking_sat
    FROM satscores sat
)

SELECT 
    sd.County,
    sd.District,
    sd.School,
    sd.school_type,
    sd.grade_level,
    hwf.`FRPM Count (K-12)` as frpm_count,
    hwf.`Enrollment (K-12)` as enrollment,
    hwf.`Percent (%) Eligible FRPM (K-12)` * 100 as percent_eligible_frpm,
    sat.NumTstTakr as num_sat_takers,
    sat.percent_taking_sat,
    sat.AvgScrRead as avg_reading,
    sat.AvgScrMath as avg_math,
    sat.AvgScrWrite as avg_writing,
    sat.total_avg_score,
    ROUND((CAST(sat.NumGE1500 AS REAL) / sat.NumTstTakr) * 100, 2) as percent_scoring_over_1500,
    hwf.frpm_rank
FROM SchoolsWithHighFRPM hwf
JOIN SchoolDetails sd ON hwf.CDSCode = sd.CDSCode
LEFT JOIN SATDetails sat ON hwf.CDSCode = sat.cds
WHERE hwf.frpm_rank <= 10
ORDER BY hwf.frpm_rank;
Database: california_schools
Question: Among the schools with the average score in Math over 560 in the SAT test, how many schools are directly charter-funded?
SQL:
SELECT COUNT(T2.`School Code`) FROM satscores AS T1 INNER JOIN frpm AS T2 ON T1.cds = T2.CDSCode WHERE T1.AvgScrMath > 560 AND T2.`Charter Funding Type` = 'Directly funded'
Database: california_schools
Question: For the school with the highest average SAT Reading score among schools with more than 10 test takers, provide comprehensive details including its location, test scores across all sections, poverty indicators, enrollment, and charter status.
Evidence: FRPM refers to Free or Reduced Price Meal program. Schools with more than 10 test takers are considered to have statistically significant results.
SQL:
WITH SchoolRankings AS (
    SELECT 
        T1.cds,
        T1.sname,
        T1.AvgScrRead,
        T1.AvgScrMath,
        T1.AvgScrWrite,
        T1.NumTstTakr,
        T1.NumGE1500,
        RANK() OVER (ORDER BY T1.AvgScrRead DESC) AS ReadingRank,
        RANK() OVER (ORDER BY T1.AvgScrMath DESC) AS MathRank,
        RANK() OVER (ORDER BY T1.AvgScrWrite DESC) AS WritingRank,
        RANK() OVER (ORDER BY (T1.AvgScrRead + T1.AvgScrMath + T1.AvgScrWrite) DESC) AS TotalScoreRank,
        (T1.NumGE1500 * 100.0 / CASE WHEN T1.NumTstTakr = 0 THEN 1 ELSE T1.NumTstTakr END) AS PercentOver1500
    FROM satscores AS T1
    WHERE T1.NumTstTakr > 10
),
TopSchools AS (
    SELECT 
        SR.cds,
        SR.sname,
        SR.AvgScrRead,
        SR.AvgScrMath,
        SR.AvgScrWrite,
        SR.ReadingRank,
        SR.MathRank,
        SR.WritingRank,
        SR.TotalScoreRank,
        SR.PercentOver1500,
        F.`FRPM Count (Ages 5-17)`,
        F.`Percent (%) Eligible FRPM (Ages 5-17)`,
        F.`Enrollment (Ages 5-17)`,
        S.County,
        S.City,
        S.Charter,
        S.GSoffered,
        S.DOCType,
        S.SOCType,
        S.EdOpsName,
        CASE 
            WHEN SR.ReadingRank <= 5 THEN 'Top 5 in Reading'
            WHEN SR.ReadingRank <= 10 THEN 'Top 10 in Reading'
            ELSE 'Other'
        END AS ReadingCategory
    FROM SchoolRankings SR
    LEFT JOIN frpm F ON SR.cds = F.CDSCode
    LEFT JOIN schools S ON SR.cds = S.CDSCode
    WHERE SR.ReadingRank <= 20
)

SELECT 
    TS.sname AS SchoolName,
    TS.County,
    TS.City,
    TS.GSoffered AS GradeSpan,
    TS.AvgScrRead AS ReadingScore,
    TS.AvgScrMath AS MathScore,
    TS.AvgScrWrite AS WritingScore,
    (TS.AvgScrRead + TS.AvgScrMath + TS.AvgScrWrite) AS TotalSATScore,
    TS.ReadingRank,
    TS.`FRPM Count (Ages 5-17)` AS FRPMCount,
    TS.`Percent (%) Eligible FRPM (Ages 5-17)` AS FRPMPercentage,
    TS.`Enrollment (Ages 5-17)` AS Enrollment,
    TS.PercentOver1500 AS PercentScoring1500Plus,
    CASE
        WHEN TS.Charter = 1 THEN 'Charter School'
        ELSE 'Non-Charter School'
    END AS SchoolType,
    CASE
        WHEN TS.`Percent (%) Eligible FRPM (Ages 5-17)` > 0.75 THEN 'High Poverty (>75%)'
        WHEN TS.`Percent (%) Eligible FRPM (Ages 5-17)` > 0.50 THEN 'Moderate Poverty (50-75%)'
        WHEN TS.`Percent (%) Eligible FRPM (Ages 5-17)` > 0.25 THEN 'Low Poverty (25-50%)'
        ELSE 'Very Low Poverty (<25%)'
    END AS PovertyLevel
FROM TopSchools TS
WHERE TS.ReadingRank = 1
ORDER BY TS.AvgScrRead DESC
LIMIT 1;
Database: california_schools
Question: For schools with total enrollment exceeding 500 students, show me their enrollment details, free meal eligibility rates, charter status, and SAT performance. Group them by county and categorize by FRPM levels (High: 75%+, Medium: 50-75%, Low: <50%). Only include schools where either the FRPM percentage is above 60% or more than 30% of SAT test takers scored 1500 or higher. Rank schools within each county by enrollment size and within each FRPM category by total SAT scores.
Evidence: Total enrollment = Enrollment (K-12) + Enrollment (Ages 5-17); FRPM percentage refers to Percent (%) Eligible FRPM (K-12); Charter schools indicated by Charter School (Y/N) = 1; Total SAT score = AvgScrRead + AvgScrMath + AvgScrWrite
SQL:
WITH HighEnrollmentSchools AS (
    SELECT 
        T2.CDSCode,
        T2.`School Name`,
        T2.`County Name`,
        T2.`Enrollment (K-12)` + T2.`Enrollment (Ages 5-17)` AS TotalEnrollment,
        T2.`Percent (%) Eligible FRPM (K-12)` * 100 AS FRPMPercentage,
        CASE 
            WHEN T2.`Percent (%) Eligible FRPM (K-12)` >= 0.75 THEN 'High FRPM'
            WHEN T2.`Percent (%) Eligible FRPM (K-12)` >= 0.50 THEN 'Medium FRPM'
            ELSE 'Low FRPM'
        END AS FRPMCategory,
        T2.`Charter School (Y/N)` AS IsCharter
    FROM schools AS T1 
    INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode
    WHERE T2.`Enrollment (K-12)` + T2.`Enrollment (Ages 5-17)` > 500
),
SchoolsWithSATScores AS (
    SELECT 
        s.cds,
        s.sname,
        s.NumTstTakr,
        s.AvgScrRead,
        s.AvgScrMath,
        s.AvgScrWrite,
        s.AvgScrRead + s.AvgScrMath + s.AvgScrWrite AS TotalSATScore,
        s.NumGE1500,
        CASE 
            WHEN s.NumTstTakr > 0 THEN CAST(s.NumGE1500 AS REAL) / s.NumTstTakr
            ELSE 0 
        END AS PercentageOver1500
    FROM satscores s
    WHERE s.rtype = 'S' -- School level records only
)
SELECT 
    h.CDSCode,
    h.`School Name`,
    h.`County Name`,
    h.TotalEnrollment,
    h.FRPMPercentage,
    h.FRPMCategory,
    CASE WHEN h.IsCharter = 1 THEN 'Yes' ELSE 'No' END AS IsCharterSchool,
    COALESCE(s.NumTstTakr, 0) AS SATTestTakers,
    COALESCE(s.TotalSATScore, 0) AS TotalSATScore,
    COALESCE(s.PercentageOver1500 * 100, 0) AS PercentageStudentsOver1500,
    RANK() OVER (PARTITION BY h.`County Name` ORDER BY h.TotalEnrollment DESC) AS CountyEnrollmentRank,
    RANK() OVER (PARTITION BY h.FRPMCategory ORDER BY COALESCE(s.TotalSATScore, 0) DESC) AS CategorySATRank
FROM HighEnrollmentSchools h
LEFT JOIN SchoolsWithSATScores s ON h.CDSCode = s.cds
WHERE (h.FRPMPercentage > 60 OR COALESCE(s.PercentageOver1500 * 100, 0) > 30)
ORDER BY h.`County Name`, CountyEnrollmentRank;
Database: california_schools
Question: Among the schools with an SAT excellence rate over 30%, which school has the highest free meal eligibility rate in its county, and what are its details?
Evidence: SAT excellence rate = NumGE1500 / NumTstTakr; Free meal eligibility rate = Free Meal Count (Ages 5-17) / Enrollment (Ages 5-17); Only active schools are considered
SQL:
WITH SchoolExcellenceRates AS (
    SELECT 
        T2.cds,
        T2.sname,
        T2.NumGE1500,
        T2.NumTstTakr,
        CAST(T2.NumGE1500 AS REAL) / T2.NumTstTakr AS excellence_rate,
        T1.`Free Meal Count (Ages 5-17)`,
        T1.`Enrollment (Ages 5-17)`,
        CAST(T1.`Free Meal Count (Ages 5-17)` AS REAL) / T1.`Enrollment (Ages 5-17)` AS eligible_free_rate,
        T3.County,
        T3.City,
        CASE 
            WHEN T3.Charter = 1 THEN 'Charter School'
            ELSE 'Non-Charter School'
        END AS school_type,
        RANK() OVER (PARTITION BY T3.County ORDER BY CAST(T1.`Free Meal Count (Ages 5-17)` AS REAL) / T1.`Enrollment (Ages 5-17)` DESC) AS county_rank
    FROM frpm AS T1 
    INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds
    INNER JOIN schools AS T3 ON T1.CDSCode = T3.CDSCode
    WHERE CAST(T2.NumGE1500 AS REAL) / T2.NumTstTakr > 0.3
    AND T1.`Enrollment (Ages 5-17)` > 0 
    AND T3.StatusType = 'Active'
)
SELECT 
    sname AS SchoolName,
    County,
    City,
    school_type,
    excellence_rate,
    eligible_free_rate,
    county_rank,
    (SELECT AVG(eligible_free_rate) FROM SchoolExcellenceRates) AS avg_eligible_free_rate,
    CASE 
        WHEN eligible_free_rate > 0.5 THEN 'High Free Meal Rate'
        WHEN eligible_free_rate > 0.25 THEN 'Medium Free Meal Rate'
        ELSE 'Low Free Meal Rate'
    END AS free_meal_category
FROM SchoolExcellenceRates
WHERE county_rank = 1
ORDER BY eligible_free_rate DESC
LIMIT 1;
Database: california_schools
Question: What are the top 3 schools ranked by SAT excellence rate, and for each school, provide their contact number, city, charter status, and poverty classification?
Evidence: SAT excellence rate = NumGE1500 / NumTstTakr. Poverty rate refers to Percent (%) Eligible FRPM (K-12). Schools are classified as High Poverty (>75%), Medium Poverty (>50%), Low Poverty (>25%), or Very Low Poverty (≤25%).
SQL:
WITH SAT_Rankings AS (
    SELECT 
        T2.cds,
        T2.sname,
        T2.NumTstTakr,
        T2.NumGE1500,
        CAST(T2.NumGE1500 AS REAL) / T2.NumTstTakr AS excellence_rate,
        RANK() OVER (ORDER BY CAST(T2.NumGE1500 AS REAL) / T2.NumTstTakr DESC) AS rank
    FROM satscores AS T2
    WHERE T2.NumTstTakr > 0
),
School_Stats AS (
    SELECT 
        s.CDSCode,
        s.School,
        s.Phone,
        s.City,
        s.Charter,
        f.`Enrollment (K-12)`,
        f.`FRPM Count (K-12)`,
        f.`Percent (%) Eligible FRPM (K-12)` AS poverty_rate,
        CASE 
            WHEN f.`Percent (%) Eligible FRPM (K-12)` > 0.75 THEN 'High Poverty'
            WHEN f.`Percent (%) Eligible FRPM (K-12)` > 0.50 THEN 'Medium Poverty'
            WHEN f.`Percent (%) Eligible FRPM (K-12)` > 0.25 THEN 'Low Poverty'
            ELSE 'Very Low Poverty'
        END AS poverty_category
    FROM schools AS s
    LEFT JOIN frpm AS f ON s.CDSCode = f.CDSCode
)
SELECT 
    r.rank AS "SAT Excellence Rank",
    r.sname AS "School Name",
    r.excellence_rate AS "SAT Excellence Rate",
    r.NumGE1500 || '/' || r.NumTstTakr AS "High Scorers/Test Takers",
    s.Phone AS "Contact Number",
    s.City AS "City",
    CASE WHEN s.Charter = 1 THEN 'Yes' ELSE 'No' END AS "Charter School",
    s.poverty_rate AS "Poverty Rate",
    s.poverty_category AS "Poverty Category"
FROM SAT_Rankings r
JOIN School_Stats s ON r.cds = s.CDSCode
WHERE r.rank <= 3
ORDER BY r.rank;
Database: california_schools
Question: List the top five schools, by descending order, from the highest to the lowest, the most number of Enrollment (Ages 5-17). Please give their NCES school identification number.
SQL:
SELECT T1.NCESSchool FROM schools AS T1 INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode ORDER BY T2.`Enrollment (Ages 5-17)` DESC LIMIT 5
Database: california_schools
Question: Which active district has the highest average score in Reading?
SQL:
SELECT T1.District, AVG(T2.AvgScrRead) AS avg_read_scr FROM schools AS T1 INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds WHERE T1.StatusType = 'Active' GROUP BY T1.District ORDER BY avg_read_scr DESC LIMIT 1
Database: california_schools
Question: How many schools in merged Alameda have number of test takers less than 100?
Evidence: 'Merged' in 'merged Alameda' refers to the schools' StatusType; Number of test takers refers to NumTstTakr
SQL:
SELECT COUNT(T1.CDSCode) FROM schools AS T1 INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds WHERE T1.StatusType = 'Merged' AND T2.NumTstTakr < 100 AND T1.County = 'Alameda'
Database: california_schools
Question: Rank schools by their average score in Writing where the score is greater than 499, showing their charter numbers.
Evidence: Valid charter number means the number is not null
SQL:
SELECT CharterNum, AvgScrWrite, RANK() OVER (ORDER BY AvgScrWrite DESC) AS WritingScoreRank FROM schools AS T1  INNER JOIN satscores AS T2 ON T1.CDSCode = T2.cds WHERE T2.AvgScrWrite > 499 AND CharterNum is not null
Database: california_schools
Question: What are the average SAT statistics and school characteristics for directly funded charter schools in Fresno County that have 250 or fewer test takers, including the breakdown by testing volume categories?
Evidence: Directly funded refers to Charter Funding Type = 'Directly funded'. Testing volume categories are: under 50 testers, 50-100 testers, and 100-250 testers.
SQL:
WITH SchoolStats AS (
    SELECT 
        f.CDSCode,
        f.`School Name`,
        f.`County Name`,
        f.`Charter Funding Type`,
        s.NumTstTakr,
        s.AvgScrRead,
        s.AvgScrMath,
        s.AvgScrWrite,
        (s.AvgScrRead + s.AvgScrMath + s.AvgScrWrite) AS TotalAvgScore,
        s.NumGE1500,
        CASE 
            WHEN s.NumTstTakr > 0 THEN CAST(s.NumGE1500 AS REAL) / s.NumTstTakr 
            ELSE 0 
        END AS PercentageGE1500,
        f.`Enrollment (K-12)`,
        f.`FRPM Count (K-12)`,
        f.`Percent (%) Eligible FRPM (K-12)`,
        sc.GSoffered,
        sc.OpenDate,
        CASE 
            WHEN sc.OpenDate IS NULL THEN NULL
            ELSE (strftime('%Y', 'now') - strftime('%Y', sc.OpenDate)) 
        END AS SchoolAge,
        ROW_NUMBER() OVER (PARTITION BY f.`County Name` ORDER BY s.NumTstTakr) AS CountyRank
    FROM frpm AS f
    INNER JOIN satscores AS s ON f.CDSCode = s.cds
    INNER JOIN schools AS sc ON f.CDSCode = sc.CDSCode
    WHERE f.`Charter Funding Type` = 'Directly funded'
)

SELECT 
    COUNT(DISTINCT ss.CDSCode) AS TotalSchools,
    ss.`County Name`,
    ROUND(AVG(ss.NumTstTakr), 2) AS AvgTestTakers,
    ROUND(AVG(ss.TotalAvgScore), 2) AS AvgTotalScore,
    ROUND(AVG(ss.PercentageGE1500) * 100, 2) AS AvgPercentScoring1500Plus,
    ROUND(AVG(ss.`Percent (%) Eligible FRPM (K-12)`) * 100, 2) AS AvgFRPMPercentage,
    ROUND(AVG(ss.SchoolAge), 1) AS AvgSchoolAgeInYears,
    COUNT(CASE WHEN ss.NumTstTakr <= 50 THEN 1 END) AS SchoolsWithUnder50Testers,
    COUNT(CASE WHEN ss.NumTstTakr > 50 AND ss.NumTstTakr <= 100 THEN 1 END) AS SchoolsWith50To100Testers,
    COUNT(CASE WHEN ss.NumTstTakr > 100 AND ss.NumTstTakr <= 250 THEN 1 END) AS SchoolsWith100To250Testers
FROM SchoolStats ss
WHERE ss.`County Name` = 'Fresno' AND ss.NumTstTakr <= 250
GROUP BY ss.`County Name`
HAVING COUNT(DISTINCT ss.CDSCode) > 0
Database: california_schools
Question: For the school with the highest average math SAT score among active schools with at least 10 test takers, provide its contact information, all SAT scores, charter status, enrollment, and percentage of students eligible for free or reduced price meals.
Evidence: Charter status refers to Charter School (Y/N) = 1 for charter schools. Free or reduced price meal eligibility refers to Percent (%) Eligible FRPM (K-12).
SQL:
WITH SchoolRankings AS (
    SELECT 
        T2.cds,
        T1.School,
        T1.Phone,
        T1.Website,
        T2.AvgScrMath,
        T2.AvgScrRead,
        T2.AvgScrWrite,
        (T2.AvgScrMath + T2.AvgScrRead + T2.AvgScrWrite) AS TotalScore,
        RANK() OVER (ORDER BY T2.AvgScrMath DESC) AS MathRank,
        RANK() OVER (ORDER BY T2.AvgScrRead DESC) AS ReadingRank,
        RANK() OVER (ORDER BY T2.AvgScrWrite DESC) AS WritingRank,
        RANK() OVER (ORDER BY (T2.AvgScrMath + T2.AvgScrRead + T2.AvgScrWrite) DESC) AS TotalRank
    FROM 
        schools AS T1
    INNER JOIN 
        satscores AS T2 ON T1.CDSCode = T2.cds
    WHERE
        T1.StatusType = 'Active'
        AND T2.NumTstTakr >= 10 -- Only consider schools with at least 10 test takers
),
CharterAnalysis AS (
    SELECT
        s.CDSCode,
        s.School,
        f.`Charter School (Y/N)` AS IsCharter,
        f.`Enrollment (K-12)` AS Enrollment,
        f.`Percent (%) Eligible FRPM (K-12)` AS PercentFRPM
    FROM
        schools s
    JOIN
        frpm f ON s.CDSCode = f.CDSCode
    WHERE
        f.`Academic Year` = '2014-2015'
)
SELECT 
    sr.School AS "Top Math School",
    sr.Phone AS "Phone Number",
    sr.Website AS "Website",
    sr.AvgScrMath AS "Math Score",
    sr.AvgScrRead AS "Reading Score",
    sr.AvgScrWrite AS "Writing Score",
    sr.TotalScore AS "Total Score",
    CASE 
        WHEN ca.IsCharter = 1 THEN 'Yes'
        ELSE 'No'
    END AS "Is Charter School",
    ca.Enrollment AS "Enrollment",
    ROUND(ca.PercentFRPM * 100, 2) || '%' AS "% Free/Reduced Price Meals",
    (SELECT COUNT(DISTINCT cds) FROM satscores) AS "Total Schools in SAT Dataset",
    (SELECT AVG(AvgScrMath) FROM satscores) AS "Average Math Score Across All Schools"
FROM 
    SchoolRankings sr
LEFT JOIN
    CharterAnalysis ca ON sr.cds = ca.CDSCode
WHERE
    sr.MathRank = 1
ORDER BY
    sr.AvgScrMath DESC
LIMIT 1;
Database: california_schools
Question: What are the key statistics for high schools in Amador County, including total number of schools, average enrollment, charter vs non-charter breakdown, average poverty rate, number of districts, SAT performance metrics, the largest school by enrollment, and how many schools have high poverty levels?
Evidence: High schools refers to Low Grade = '9' AND High Grade = '12'; High poverty schools are those where Percent (%) Eligible FRPM (K-12) > 0.75; Charter schools refers to Charter School (Y/N) = 1
SQL:
WITH SchoolInfo AS (
    SELECT 
        s.CDSCode,
        s.County,
        s.School,
        s.District,
        f.`Low Grade`,
        f.`High Grade`,
        f.`Enrollment (K-12)` AS Enrollment,
        f.`Charter School (Y/N)` AS IsCharter,
        f.`FRPM Count (K-12)` AS FRPMCount,
        f.`Percent (%) Eligible FRPM (K-12)` AS FRPMPercent,
        CASE 
            WHEN f.`Percent (%) Eligible FRPM (K-12)` > 0.75 THEN 'High Poverty'
            WHEN f.`Percent (%) Eligible FRPM (K-12)` > 0.50 THEN 'Medium Poverty'
            WHEN f.`Percent (%) Eligible FRPM (K-12)` > 0.25 THEN 'Low Poverty'
            ELSE 'Very Low Poverty'
        END AS PovertyLevel,
        RANK() OVER (PARTITION BY s.County ORDER BY f.`Enrollment (K-12)` DESC) AS EnrollmentRank
    FROM schools AS s
    INNER JOIN frpm AS f ON s.CDSCode = f.CDSCode
    WHERE s.County = 'Amador' AND f.`Low Grade` = '9' AND f.`High Grade` = '12'
),
SATData AS (
    SELECT 
        si.CDSCode,
        si.School,
        si.County,
        si.District,
        sat.NumTstTakr,
        sat.AvgScrRead,
        sat.AvgScrMath,
        sat.AvgScrWrite,
        (sat.AvgScrRead + sat.AvgScrMath + sat.AvgScrWrite) AS TotalAvgScore,
        (sat.NumGE1500 * 1.0 / NULLIF(sat.NumTstTakr, 0)) * 100 AS PercentAbove1500
    FROM SchoolInfo si
    LEFT JOIN satscores sat ON si.CDSCode = sat.cds
)
SELECT 
    COUNT(si.School) AS TotalSchools,
    AVG(si.Enrollment) AS AvgEnrollment,
    SUM(CASE WHEN si.IsCharter = 1 THEN 1 ELSE 0 END) AS CharterSchools,
    SUM(CASE WHEN si.IsCharter = 0 THEN 1 ELSE 0 END) AS NonCharterSchools,
    AVG(si.FRPMPercent) * 100 AS AvgFRPMPercentage,
    (SELECT COUNT(DISTINCT District) FROM SchoolInfo) AS DistrictCount,
    (SELECT AVG(TotalAvgScore) FROM SATData WHERE NumTstTakr > 0) AS AvgSATScore,
    (SELECT MAX(PercentAbove1500) FROM SATData WHERE NumTstTakr > 0) AS MaxPercentAbove1500,
    (SELECT School FROM SchoolInfo WHERE EnrollmentRank = 1) AS LargestSchool,
    (SELECT COUNT(*) FROM SchoolInfo WHERE PovertyLevel = 'High Poverty') AS HighPovertySchools
FROM SchoolInfo si
Database: california_schools
Question: For Los Angeles schools with more than 500 free meals but less than 700 FRPM meals for K-12 students, what is the average percentage of students receiving free meals, how many are charter versus non-charter schools, what is their average SAT score, and how are they distributed across free meal categories?
Evidence: Free meal percentage = Free Meal Count (K-12) / Enrollment (K-12) * 100. Schools are categorized as 'Very High' if free meals > 600, 'High' if > 500, otherwise 'Moderate'. Charter schools have Charter = 1.
SQL:
WITH SchoolMealStats AS (
    SELECT 
        f.CDSCode,
        f.`School Name`,
        f.`County Name`,
        f.`Free Meal Count (K-12)` AS FreeMeals,
        f.`FRPM Count (K-12)` AS TotalFRPM,
        f.`Enrollment (K-12)` AS Enrollment,
        ROUND(f.`Free Meal Count (K-12)` / f.`Enrollment (K-12)` * 100, 2) AS FreePercentage,
        ROUND(f.`FRPM Count (K-12)` / f.`Enrollment (K-12)` * 100, 2) AS FRPMPercentage,
        s.Street,
        s.City,
        s.Charter,
        s.GSoffered AS GradeSpan,
        CASE 
            WHEN f.`Free Meal Count (K-12)` > 600 THEN 'Very High'
            WHEN f.`Free Meal Count (K-12)` > 500 THEN 'High'
            ELSE 'Moderate'
        END AS FreeMealCategory
    FROM frpm f
    JOIN schools s ON f.CDSCode = s.CDSCode
    WHERE f.`County Name` = 'Los Angeles'
      AND f.`Free Meal Count (K-12)` > 500
      AND f.`FRPM Count (K-12)` < 700
),
SATData AS (
    SELECT 
        cds,
        sname,
        NumTstTakr,
        AvgScrRead + AvgScrMath + AvgScrWrite AS TotalSATScore,
        CAST(NumGE1500 AS FLOAT) / NULLIF(NumTstTakr, 0) * 100 AS PercentOver1500
    FROM satscores
    WHERE cname = 'Los Angeles'
),
CategoryBreakdown AS (
    SELECT 
        FreeMealCategory, 
        COUNT(*) AS CategoryCount
    FROM SchoolMealStats
    GROUP BY FreeMealCategory
)
SELECT 
    COUNT(DISTINCT sms.CDSCode) AS TotalSchools,
    AVG(sms.FreeMeals) AS AvgFreeMeals,
    AVG(sms.TotalFRPM) AS AvgTotalFRPM,
    AVG(sms.FreePercentage) AS AvgFreePercentage,
    AVG(sms.FRPMPercentage) AS AvgFRPMPercentage,
    SUM(CASE WHEN sms.Charter = 1 THEN 1 ELSE 0 END) AS CharterSchoolCount,
    SUM(CASE WHEN sms.Charter = 0 THEN 1 ELSE 0 END) AS NonCharterSchoolCount,
    AVG(CASE WHEN sd.TotalSATScore IS NOT NULL THEN sd.TotalSATScore ELSE NULL END) AS AvgSATScore,
    (SELECT COUNT(DISTINCT sms2.CDSCode) 
     FROM SchoolMealStats sms2 
     LEFT JOIN SATData sd2 ON sms2.CDSCode = sd2.cds 
     WHERE sd2.cds IS NULL) AS SchoolsWithoutSATData,
    (SELECT GROUP_CONCAT(FreeMealCategory || ': ' || CategoryCount) 
     FROM CategoryBreakdown) AS FreeMealCategoryBreakdown
FROM SchoolMealStats sms
LEFT JOIN SATData sd ON sms.CDSCode = sd.cds;
Database: california_schools
Question: Which school in Contra Costa has the highest number of test takers?
SQL:
SELECT sname FROM satscores WHERE cname = 'Contra Costa' AND sname IS NOT NULL ORDER BY NumTstTakr DESC LIMIT 1
Database: california_schools
Question: List the names of schools with more than 30 difference in enrollements between K-12 and ages 5-17? Please also give the full street adress of the schools.
Evidence: Diffrence in enrollement = `Enrollment (K-12)` - `Enrollment (Ages 5-17)`
SQL:
SELECT T1.School, T1.Street
FROM schools AS T1
INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode
WHERE T2.`Enrollment (K-12)` - T2.`Enrollment (Ages 5-17)` > 30;
Database: california_schools
Question: Give the names of the schools with the percent eligible for free meals in K-12 is more than 0.1 and test takers whose test score is greater than or equal to 1500?
Evidence: Percent eligible for free meals = Free Meal Count (K-12) / Total (Enrollment (K-12)
SQL:
SELECT T2.`School Name` FROM satscores AS T1 INNER JOIN frpm AS T2 ON T1.cds = T2.CDSCode WHERE CAST(T2.`Free Meal Count (K-12)` AS REAL) / T2.`Enrollment (K-12)` > 0.1 AND T1.NumGE1500 > 0
Database: california_schools
Question: Name schools in Riverside which the average of average math score for SAT is grater than 400, what is the type of educational option that these school provides?
Evidence: Average of average math = sum(average math scores) / count(schools).
SQL:
SELECT T1.sname, T2.`Educational Option Type` FROM satscores AS T1 INNER JOIN frpm AS T2 ON T1.cds = T2.CDSCode WHERE T2.`District Name` LIKE 'Riverside%' GROUP BY T1.sname, T2.`Educational Option Type` HAVING CAST(SUM(T1.AvgScrMath) AS REAL) / COUNT(T1.cds) > 400
Database: california_schools
Question: State the names and full communication addresses of high schools in Monterey that offer more than 800 free or reduced-priced meals for ages 15-17.
Evidence: Full communication address should include Street, City, State and zip code if any.
Free or reduced price meals can be shortened to FRPM.
SQL:
SELECT T1.`School Name`, T2.Street, T2.City, T2.State, T2.Zip FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.County = 'Monterey' AND T1.`FRPM Count (Ages 5-17)` > 800 AND T1.`School Type` = 'High Schools (Public)'
Database: california_schools
Question: What is the average score in writing for the schools that were opened after 1991 or closed before 2000? List the school names along with the score. Also, list the communication number of the schools if there is any.
Evidence: Communication number refers to phone number.
SQL:
SELECT T2.School, T1.AvgScrWrite, T2.Phone FROM schools AS T2 LEFT JOIN satscores AS T1 ON T2.CDSCode = T1.cds WHERE strftime('%Y', T2.OpenDate) > '1991' OR strftime('%Y', T2.ClosedDate) < '2000'
Database: california_schools
Question: Consider the average difference between K-12 enrollment and 15-17 enrollment of schools that are locally funded, list the names and DOC type of schools which has a difference above this average.
Evidence: Difference between K-12 enrollment and 15-17 enrollment can be computed by `Enrollment (K-12)` - `Enrollment (Ages 5-17)`
SQL:
SELECT T2.School, T2.DOC FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T2.FundingType = 'Locally funded' AND (T1.`Enrollment (K-12)` - T1.`Enrollment (Ages 5-17)`) > (SELECT AVG(T3.`Enrollment (K-12)` - T3.`Enrollment (Ages 5-17)`) FROM frpm AS T3 INNER JOIN schools AS T4 ON T3.CDSCode = T4.CDSCode WHERE T4.FundingType = 'Locally funded')
Database: california_schools
Question: When did the first-through-twelfth-grade school with the largest enrollment open?
Evidence: K-12 means First-through-twelfth-grade
SQL:
SELECT T2.OpenDate FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode ORDER BY T1.`Enrollment (K-12)` DESC LIMIT 1
Database: california_schools
Question: Which cities have the top 5 lowest enrollment number for students in grades 1 through 12?
Evidence: K-12 refers to students in grades 1 through 12.
SQL:
SELECT T2.City FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode GROUP BY T2.City ORDER BY SUM(T1.`Enrollment (K-12)`) ASC LIMIT 5
Database: california_schools
Question: For the 10th and 11th largest schools by K-12 enrollment, provide a comprehensive profile including their enrollment statistics, free meal eligibility rates, location details, school type, grade spans offered, and SAT performance metrics.
Evidence: K-12 refers to students in grades 1 through 12; Eligible free rate for K-12 = Free Meal Count (K-12) / Enrollment (K-12); Charter schools have Charter = 1
SQL:
WITH EnrollmentRanked AS (
    SELECT 
        f.CDSCode,
        f.`School Name`,
        f.`District Name`,
        f.`County Name`,
        f.`Enrollment (K-12)`,
        f.`Free Meal Count (K-12)`,
        CAST(f.`Free Meal Count (K-12)` AS REAL) / f.`Enrollment (K-12)` AS EligibleFreeRate,
        ROW_NUMBER() OVER (ORDER BY f.`Enrollment (K-12)` DESC) AS EnrollmentRank
    FROM frpm f
    WHERE f.`Enrollment (K-12)` > 0
),
SchoolDetails AS (
    SELECT 
        s.CDSCode,
        s.School,
        s.City,
        s.Charter,
        s.GSoffered,
        s.Website,
        CASE 
            WHEN s.Charter = 1 THEN 'Charter School'
            ELSE 'Regular School'
        END AS SchoolType,
        CASE
            WHEN s.Latitude IS NOT NULL AND s.Longitude IS NOT NULL THEN 'Yes'
            ELSE 'No'
        END AS HasGeolocation
    FROM schools s
),
SATPerformance AS (
    SELECT
        sat.cds,
        sat.NumTstTakr,
        sat.AvgScrRead,
        sat.AvgScrMath,
        sat.AvgScrWrite,
        sat.NumGE1500,
        CASE 
            WHEN sat.NumTstTakr > 0 THEN CAST(sat.NumGE1500 AS REAL) / sat.NumTstTakr
            ELSE 0
        END AS PercentageAbove1500
    FROM satscores sat
)
SELECT 
    e.EnrollmentRank,
    e.`School Name`,
    e.`District Name`,
    e.`County Name`,
    e.`Enrollment (K-12)` AS TotalEnrollment,
    e.`Free Meal Count (K-12)` AS FreeMealCount,
    ROUND(e.EligibleFreeRate * 100, 2) || '%' AS EligibleFreeRate,
    sd.City,
    sd.SchoolType,
    sd.GSoffered AS GradeSpan,
    sd.Website,
    COALESCE(sp.NumTstTakr, 0) AS SATTestTakers,
    COALESCE(sp.AvgScrRead, 0) AS AvgReadingScore,
    COALESCE(sp.AvgScrMath, 0) AS AvgMathScore,
    COALESCE(sp.AvgScrWrite, 0) AS AvgWritingScore,
    COALESCE(ROUND(sp.PercentageAbove1500 * 100, 2), 0) || '%' AS PercentAbove1500SAT
FROM EnrollmentRanked e
LEFT JOIN SchoolDetails sd ON e.CDSCode = sd.CDSCode
LEFT JOIN SATPerformance sp ON e.CDSCode = sp.cds
WHERE e.EnrollmentRank IN (10, 11)
ORDER BY e.EnrollmentRank;
Database: california_schools
Question: For the top 5 schools with the highest number of students eligible for free or reduced price meals in grades K-12 among schools with ownership code 66, what are their eligibility rates, SAT performance metrics, and how do they compare in terms of SAT participation and high scorer rates?
Evidence: Eligible free or reduced price meal rate for K-12 = FRPM Count (K-12) / Enrollment (K-12); ownership code 66 refers to SOC = '66'; high scorer rate refers to students scoring 1500 or above on SAT
SQL:
WITH SchoolEligibilityRanking AS (
    SELECT 
        T1.CDSCode,
        T2.School,
        T2.County,
        T2.District,
        T2.SOCType,
        T1.`Enrollment (K-12)`,
        T1.`FRPM Count (K-12)`,
        CAST(T1.`FRPM Count (K-12)` AS REAL) / T1.`Enrollment (K-12)` AS EligibilityRate,
        RANK() OVER (ORDER BY T1.`FRPM Count (K-12)` DESC) AS FRPMRank
    FROM frpm AS T1
    INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode
    WHERE T2.SOC = '66'
    AND T1.`Enrollment (K-12)` > 0
),
SATPerformance AS (
    SELECT 
        s.cds,
        s.NumTstTakr,
        s.AvgScrRead,
        s.AvgScrMath,
        s.AvgScrWrite,
        s.AvgScrRead + s.AvgScrMath + s.AvgScrWrite AS TotalSATScore,
        CAST(s.NumGE1500 AS REAL) / NULLIF(s.NumTstTakr, 0) AS HighScorerRate
    FROM satscores s
    WHERE s.rtype = 'S' -- School level records only
)
SELECT 
    r.FRPMRank,
    r.School,
    r.County,
    r.District,
    r.SOCType,
    r.`Enrollment (K-12)` AS Enrollment,
    r.`FRPM Count (K-12)` AS FRPMCount,
    ROUND(r.EligibilityRate * 100, 2) || '%' AS EligibilityRate,
    CASE 
        WHEN r.EligibilityRate >= 0.75 THEN 'Very High FRPM'
        WHEN r.EligibilityRate >= 0.50 THEN 'High FRPM'
        WHEN r.EligibilityRate >= 0.25 THEN 'Moderate FRPM'
        ELSE 'Low FRPM'
    END AS EligibilityCategory,
    s.NumTstTakr AS SATTestTakers,
    s.AvgScrRead AS AvgReading,
    s.AvgScrMath AS AvgMath,
    s.AvgScrWrite AS AvgWriting,
    s.TotalSATScore,
    ROUND(COALESCE(s.HighScorerRate * 100, 0), 2) || '%' AS HighSATScorerRate,
    ROUND((CAST(s.NumTstTakr AS REAL) / NULLIF(r.`Enrollment (K-12)`, 0)) * 100, 2) || '%' AS SATParticipationRate
FROM SchoolEligibilityRanking r
LEFT JOIN SATPerformance s ON r.CDSCode = s.cds
WHERE r.FRPMRank <= 5
ORDER BY r.FRPMRank;
Database: california_schools
Question: If there are any, what are the websites address of the schools with a free meal count of 1,900-2,000 to students aged 5-17? Include the name of the school.
SQL:
SELECT T2.Website, T1.`School Name` FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T1.`Free Meal Count (Ages 5-17)` BETWEEN 1900 AND 2000 AND T2.Website IS NOT NULL
Database: california_schools
Question: What is the free rate for students between the ages of 5 and 17 at the school run by Kacey Gibson?
Evidence: Eligible free rates for students aged 5-17 = `Free Meal Count (Ages 5-17)` / `Enrollment (Ages 5-17)`
SQL:
SELECT CAST(T2.`Free Meal Count (Ages 5-17)` AS REAL) / T2.`Enrollment (Ages 5-17)` FROM schools AS T1 INNER JOIN frpm AS T2 ON T1.CDSCode = T2.CDSCode WHERE T1.AdmFName1 = 'Kacey' AND T1.AdmLName1 = 'Gibson'
Database: california_schools
Question: What is the administrator's email address of the chartered school with the fewest students enrolled in grades 1 through 12?
Evidence: Chartered schools are identified by a binary indicator where 1 represents a chartered school. Students enrolled in grades 1 through 12 refers to the total enrollment count for those grade levels.
SQL:
SELECT T2.AdmEmail1 FROM frpm AS T1 INNER JOIN schools AS T2 ON T1.CDSCode = T2.CDSCode WHERE T1.`Charter School (Y/N)` = 1 ORDER BY T1.`Enrollment (K-12)` ASC, T1.CDSCode ASC LIMIT 1
Database: california_schools
Question: Under whose administration is the school with the highest number of students scoring 1500 or more on the SAT? Indicate their full names.
Evidence: full name means first name, last name; There are at most 3 administrators for each school; SAT Scores are greater or equal to 1500 refers to NumGE1500
SQL:
SELECT T2.AdmFName1, T2.AdmLName1, T2.AdmFName2, T2.AdmLName2, T2.AdmFName3, T2.AdmLName3 FROM satscores AS T1 INNER JOIN schools AS T2 ON T1.cds = T2.CDSCode ORDER BY T1.NumGE1500 DESC LIMIT 1