Generate SQL statements based on the table contents and problems. If the SQL statement cannot be given directly from the table, the SQL statement can contain some sub-problems. Then divide the problem into multiple sub-problems according to the logic of the SQL statement.
Write the SQL statement behind the 'SQL:', and write the sub-question behind the 'Decompose:'.

#
Table:
/*
table caption : stay in office
| name | took office | left office | party |
|---:|-------:|:-------------------|:-------|:----|----------------------:|
| William McCreery | March 4, 1803 | March 3, 1809 | Democratic Republican |
| Alexander McKim | March 4, 1809 | March 3, 1815 | Democratic Republican |
| William Pinkney | March 4, 1815 | April 18, 1816 | Democratic Republican |
| Peter Little | September 2, 1816 | March 3, 1823 | Democratic Republican |
| Peter Little | March 4, 1823 | March 3, 1825 | Jacksonian DR |
| Peter Little | March 4, 1825 | March 3, 1829 | Adams |
| Benjamin C. Howard | March 4, 1829 | March 3, 1833 | Jacksonian |
*/

Question:
How many people stayed at least 3 years in office?

SQL:
SELECT COUNT(*) FROM (SELECT name, julianday(left_office) - julianday(took_office) AS duration_days FROM office_terms) AS durations WHERE duration_days >= 365 * 3;

Decompose:
1. Calculate the duration in office.
2. Filter those with at least 3 years in office.
3. Count the number of people who meet the criteria.
#


#
Table:
/*
table caption : Portland Timbers (2001–10)
| year | division | league | regular season | playoffs | open cup | avg. attendance |
|---:|-------:|:-------------------|:-------|:----|----------------------:|
| 2001 | 2 | usl a-league | 4th, western | quarterfinals | did not qualify | 7,169 |
| 2002 | 2 | usl a-league | 2nd, pacific | 1st round | did not qualify | 6,260 |
| 2003 | 2 | usl a-league | 3rd, pacific | did not qualify | did not qualify | 5,871 |
| 2004 | 2 | usl a-league | 1st, western | quarterfinals | 4th round | 5,628 |
| 2005 | 2 | usl first division | 5th | quarterfinals | 4th round | 6,028 |
| 2006 | 2 | usl first division | 11th | did not qualify | 3rd round | 5,575 |
| 2007 | 2 | usl first division | 2nd | semifinals | 2nd round | 6,851 |
| 2008 | 2 | usl first division | 11th | did not qualify | 1st round | 8,567 |
| 2009 | 2 | usl first division | 1st | semifinals | 3rd round | 9,734 |
| 2010 | 2 | ussf d-2 pro league | 3rd, usl (3rd) | quarterfinals | 3rd round | 10,727 |
*/

Question:
What was the last year where this team was a part of the usl a-league?

SQL:
SELECT MAX(year) AS last_year_in_usl_a_league FROM team_performance WHERE league = 'usl a-league';

Decompose:
1. Filter the records to only include those where the league is 'usl a-league'.
2. Find the maximum year from the filtered records.
#


#
Table:
/*
| constituency number | name | reserved for (sc/st/none) | district | number of electorates (2009) |
|---:|-------:|:-------------------|:-------|:----|----------------------:|
| 43 | tikamgarh | none | tikamgarh | 153,339 |
| 44 | jatara | sc | tikamgarh | 145,555 |
| 45 | prithvipur | none | tikamgarh | 139,110 |
| 46 | niwari | none | tikamgarh | 141,265 |
| 47 | khargapur | none | tikamgarh | 161,546 |
| 48 | maharajpur | none | chhatarpur | 162,460 |
| 51 | chhatarpur | none | chhatarpur | 152,605 |
| 52 | bijawar | none | chhatarpur | 151,159 |
| total : total | total | total | total | 1,207,039 |
*/

Question:
Which district has the greatest total number of electorates?

SQL:
SELECT district, SUM("number of electorates (2009)") AS total_electorates FROM constituencies GROUP BY district ORDER BY total_electorates DESC LIMIT 1;

Decompose:
1. Sum the number of electorates for each district.
2. Order the results by the total number of electorates in descending order.
3. Limit the result to the top district.
#


#
Table:
/*
table caption : {TITLE}
{TABLE}
*/

Question:
{QUESTION}