Task: NL2SQL (source dataset: bird)

Natural language to SQL, also known as NL2SQL, is the problem of generating a SQL query that can be executed on a input table, for a given natural language question.

You will be given an input table called "table" in the markdown format, as well as a question. Your task is to generate an SQL query that can be executed on the input table to answer the question.

Please ensure that the generated SQL only return relevant columns being specifically asked in the question (e.g., in SQL please don't return more than one columns in SELECT if only one column is needed to answer the given question, and similarly please refrain from using SELECT * unless the entire row is needed to answer the question).
 
When generating SQL code, please use the SQLite syntax to ensure that your SQL is executable on SQLite3. Use only columns that are present in the table, always use quotes around your column and table names (some column names have punctuation or special characters), and refer to the columns using the column-names exactly as they appear in the table, do not add or remove punctuation (underscore, slash, etc.)

No explanation, return the code only with the following markdown codeblock format : ```sql<SQL CODE>```. For example, ```sql
SELECT * FROM "table"
``` is a valid format.

Database:
financial

Tables:

Table: account
|   account_id |   district_id | frequency        | date       |
|-------------:|--------------:|:-----------------|:-----------|
|            1 |            18 | POPLATEK MESICNE | 1995-03-24 |
|            2 |             1 | POPLATEK MESICNE | 1993-02-26 |
|            3 |             5 | POPLATEK MESICNE | 1997-07-07 |
|            4 |            12 | POPLATEK MESICNE | 1996-02-21 |
|            5 |            15 | POPLATEK MESICNE | 1997-05-30 |
|            6 |            51 | POPLATEK MESICNE | 1994-09-27 |
|            7 |            60 | POPLATEK MESICNE | 1996-11-24 |
|            8 |            57 | POPLATEK MESICNE | 1995-09-21 |
|            9 |            70 | POPLATEK MESICNE | 1993-01-27 |
|           10 |            54 | POPLATEK MESICNE | 1996-08-28 |


Table: card
|   card_id |   disp_id | type    | issued     |
|----------:|----------:|:--------|:-----------|
|         1 |         9 | gold    | 1998-10-16 |
|         2 |        19 | classic | 1998-03-13 |
|         3 |        41 | gold    | 1995-09-03 |
|         4 |        42 | classic | 1998-11-26 |
|         5 |        51 | junior  | 1995-04-24 |
|         7 |        56 | classic | 1998-06-11 |
|         8 |        60 | junior  | 1998-05-20 |
|         9 |        76 | classic | 1997-10-25 |
|        10 |        77 | classic | 1996-12-07 |
|        11 |        79 | gold    | 1997-10-25 |


Table: client
|   client_id | gender   | birth_date   |   district_id |
|------------:|:---------|:-------------|--------------:|
|           1 | F        | 1970-12-13   |            18 |
|           2 | M        | 1945-02-04   |             1 |
|           3 | F        | 1940-10-09   |             1 |
|           4 | M        | 1956-12-01   |             5 |
|           5 | F        | 1960-07-03   |             5 |
|           6 | M        | 1919-09-22   |            12 |
|           7 | M        | 1929-01-25   |            15 |
|           8 | F        | 1938-02-21   |            51 |
|           9 | M        | 1935-10-16   |            60 |
|          10 | M        | 1943-05-01   |            57 |


Table: disp
|   disp_id |   client_id |   account_id | type      |
|----------:|------------:|-------------:|:----------|
|         1 |           1 |            1 | OWNER     |
|         2 |           2 |            2 | OWNER     |
|         3 |           3 |            2 | DISPONENT |
|         4 |           4 |            3 | OWNER     |
|         5 |           5 |            3 | DISPONENT |
|         6 |           6 |            4 | OWNER     |
|         7 |           7 |            5 | OWNER     |
|         8 |           8 |            6 | OWNER     |
|         9 |           9 |            7 | OWNER     |
|        10 |          10 |            8 | OWNER     |


Table: district
|   district_id | A2             | A3              |      A4 |   A5 |   A6 |   A7 |   A8 |   A9 |   A10 |   A11 |   A12 |   A13 |   A14 |   A15 |   A16 |
|--------------:|:---------------|:----------------|--------:|-----:|-----:|-----:|-----:|-----:|------:|------:|------:|------:|------:|------:|------:|
|             1 | Hl.m. Praha    | Prague          | 1204953 |    0 |    0 |    0 |    1 |    1 | 100   | 12541 |   0.2 |  0.43 |   167 | 85677 | 99107 |
|             2 | Benesov        | central Bohemia |   88884 |   80 |   26 |    6 |    2 |    5 |  46.7 |  8507 |   1.6 |  1.85 |   132 |  2159 |  2674 |
|             3 | Beroun         | central Bohemia |   75232 |   55 |   26 |    4 |    1 |    5 |  41.7 |  8980 |   1.9 |  2.21 |   111 |  2824 |  2813 |
|             4 | Kladno         | central Bohemia |  149893 |   63 |   29 |    6 |    2 |    6 |  67.4 |  9753 |   4.6 |  5.05 |   109 |  5244 |  5892 |
|             5 | Kolin          | central Bohemia |   95616 |   65 |   30 |    4 |    1 |    6 |  51.4 |  9307 |   3.8 |  4.43 |   118 |  2616 |  3040 |
|             6 | Kutna Hora     | central Bohemia |   77963 |   60 |   23 |    4 |    2 |    4 |  51.5 |  8546 |   2.9 |  4.02 |   126 |  2640 |  3120 |
|             7 | Melnik         | central Bohemia |   94725 |   38 |   28 |    1 |    3 |    6 |  63.4 |  9920 |   2.2 |  2.87 |   130 |  4289 |  4846 |
|             8 | Mlada Boleslav | central Bohemia |  112065 |   95 |   19 |    7 |    1 |    8 |  69.4 | 11277 |   1.2 |  1.44 |   127 |  5179 |  4987 |
|             9 | Nymburk        | central Bohemia |   81344 |   61 |   23 |    4 |    2 |    6 |  55.3 |  8899 |   3.3 |  3.97 |   149 |  2987 |  2487 |
|            10 | Praha - vychod | central Bohemia |   92084 |   55 |   29 |    4 |    3 |    5 |  46.7 | 10124 |   0.5 |  0.54 |   141 |  3810 |  4316 |


Table: loan
|   loan_id |   account_id | date       |   amount |   duration |   payments | status   |
|----------:|-------------:|:-----------|---------:|-----------:|-----------:|:---------|
|      4959 |            2 | 1994-01-05 |    80952 |         24 |       3373 | A        |
|      4961 |           19 | 1996-04-29 |    30276 |         12 |       2523 | B        |
|      4962 |           25 | 1997-12-08 |    30276 |         12 |       2523 | A        |
|      4967 |           37 | 1998-10-14 |   318480 |         60 |       5308 | D        |
|      4968 |           38 | 1998-04-19 |   110736 |         48 |       2307 | C        |
|      4973 |           67 | 1996-05-02 |   165960 |         24 |       6915 | A        |
|      4986 |           97 | 1997-08-10 |   102876 |         12 |       8573 | A        |
|      4988 |          103 | 1997-12-06 |   265320 |         36 |       7370 | D        |
|      4989 |          105 | 1998-12-05 |   352704 |         48 |       7348 | C        |
|      4990 |          110 | 1997-09-08 |   162576 |         36 |       4516 | C        |


Table: order
|   order_id |   account_id | bank_to   |   account_to |   amount | k_symbol   |
|-----------:|-------------:|:----------|-------------:|---------:|:-----------|
|      29401 |            1 | YZ        |     87144583 |   2452   | SIPO       |
|      29402 |            2 | ST        |     89597016 |   3372.7 | UVER       |
|      29403 |            2 | QR        |     13943797 |   7266   | SIPO       |
|      29404 |            3 | WX        |     83084338 |   1135   | SIPO       |
|      29405 |            3 | CD        |     24485939 |    327   |            |
|      29406 |            3 | AB        |     59972357 |   3539   | POJISTNE   |
|      29407 |            4 | UV        |     26693541 |   2078   | SIPO       |
|      29408 |            4 | UV        |      5848086 |   1285   | SIPO       |
|      29409 |            5 | GH        |     37390208 |   2668   | SIPO       |
|      29410 |            6 | AB        |     44486999 |   3954   | SIPO       |


Table: trans
|   trans_id |   account_id | date       | type   | operation     |   amount |   balance | k_symbol   | bank   | account    |
|-----------:|-------------:|:-----------|:-------|:--------------|---------:|----------:|:-----------|:-------|:-----------|
|          1 |            1 | 1995-03-24 | PRIJEM | VKLAD         |     1000 |      1000 |            |        |            |
|          5 |            1 | 1995-04-13 | PRIJEM | PREVOD Z UCTU |     3679 |      4679 |            | AB     | 41403269.0 |
|          6 |            1 | 1995-05-13 | PRIJEM | PREVOD Z UCTU |     3679 |     20977 |            | AB     | 41403269.0 |
|          7 |            1 | 1995-06-13 | PRIJEM | PREVOD Z UCTU |     3679 |     26835 |            | AB     | 41403269.0 |
|          8 |            1 | 1995-07-13 | PRIJEM | PREVOD Z UCTU |     3679 |     30415 |            | AB     | 41403269.0 |
|          9 |            1 | 1995-08-13 | PRIJEM | PREVOD Z UCTU |     3679 |     28903 |            | AB     | 41403269.0 |
|         10 |            1 | 1995-09-13 | PRIJEM | PREVOD Z UCTU |     3679 |     22714 |            | AB     | 41403269.0 |
|         11 |            1 | 1995-10-13 | PRIJEM | PREVOD Z UCTU |     3679 |     23318 |            | AB     | 41403269.0 |
|         12 |            1 | 1995-11-13 | PRIJEM | PREVOD Z UCTU |     3679 |     21721 |            | AB     | 41403269.0 |
|         13 |            1 | 1995-12-13 | PRIJEM | PREVOD Z UCTU |     3679 |     20249 |            | AB     | 41403269.0 |


Question: What is the average amount of loan which are still on running contract with statement issuance after each transaction?

db_id: financial
tables: name: account
data: account.csv
name: card
data: card.csv
name: client
data: client.csv
name: disp
data: disp.csv
name: district
data: district.csv
name: loan
data: loan.csv
name: order
data: order.csv
name: trans
data: trans.csv
label: SELECT AVG(T2.amount) FROM account AS T1 INNER JOIN loan AS T2 ON T1.account_id = T2.account_id WHERE T2.status IN ('C', 'D') AND T1.frequency = 'POPLATEK PO OBRATU'
sqlite_path: $MMTU_HOME/data_sqlite/bird/dev_20240627/dev_databases/financial/financial.sqlite