sert121/SpiderSQL huggingface dataset:
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: List all the distinct cities
SQL: SELECT DISTINCT city FROM addresses
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Find the city with post code 255.
SQL: SELECT city FROM addresses WHERE zip_postcode  =  255
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Which city is post code 255 located in?
SQL: SELECT city FROM addresses WHERE zip_postcode  =  255
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Find the state and country of all cities with post code starting with 4.
SQL: SELECT state_province_county ,  country FROM addresses WHERE zip_postcode LIKE "4%"
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: What are the state and country of all the cities that have post codes starting with 4.\
SQL: SELECT state_province_county ,  country FROM addresses WHERE zip_postcode LIKE "4%"
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: List the countries having more than 4 addresses listed.
SQL: SELECT country FROM addresses GROUP BY country HAVING count(address_id)  >  4
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: For which countries are there more than four distinct addresses listed?
SQL: SELECT country FROM addresses GROUP BY country HAVING count(address_id)  >  4
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: List all the contact channel codes that were used less than 5 times.
SQL: SELECT channel_code FROM customer_contact_channels GROUP BY channel_code HAVING count(customer_id)  <  5
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Which contact channel codes were used less than 5 times?
SQL: SELECT channel_code FROM customer_contact_channels GROUP BY channel_code HAVING count(customer_id)  <  5
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Which contact channel has been used by the customer with name "Tillman Ernser"?
SQL: SELECT DISTINCT channel_code FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id  =  t2.customer_id WHERE t1.customer_name  =  "Tillman Ernser"
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Find the contact channel code that was used by the customer named "Tillman Ernser".
SQL: SELECT DISTINCT channel_code FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id  =  t2.customer_id WHERE t1.customer_name  =  "Tillman Ernser"
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: What is the "active to date" of the latest contact channel used by "Tillman Ernser"?
SQL: SELECT max(t2.active_to_date) FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id  =  t2.customer_id WHERE t1.customer_name  =  "Tillman Ernser"
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Return the the "active to date" of the latest contact channel used by the customer named "Tillman Ernser".
SQL: SELECT max(t2.active_to_date) FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id  =  t2.customer_id WHERE t1.customer_name  =  "Tillman Ernser"
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: What is the average time span of contact channels in the database?
SQL: SELECT avg(active_to_date - active_from_date) FROM customer_contact_channels
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Compute the average active time span of contact channels.
SQL: SELECT avg(active_to_date - active_from_date) FROM customer_contact_channels
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: What is the channel code and contact number of the customer contact channel that was active for the longest time?
SQL: SELECT channel_code ,  contact_number FROM customer_contact_channels WHERE active_to_date - active_from_date  =  (SELECT active_to_date - active_from_date FROM customer_contact_channels ORDER BY (active_to_date - active_from_date) DESC LIMIT 1)
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Return the channel code and contact number of the customer contact channel whose active duration was the longest.
SQL: SELECT channel_code ,  contact_number FROM customer_contact_channels WHERE active_to_date - active_from_date  =  (SELECT active_to_date - active_from_date FROM customer_contact_channels ORDER BY (active_to_date - active_from_date) DESC LIMIT 1)
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Find the name and active date of the customer that use email as the contact channel.
SQL: SELECT t1.customer_name ,  t2.active_from_date FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id  =  t2.customer_id WHERE t2.channel_code  =  'Email'
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: What are the name and active date of the customers whose contact channel code is email?
SQL: SELECT t1.customer_name ,  t2.active_from_date FROM customers AS t1 JOIN customer_contact_channels AS t2 ON t1.customer_id  =  t2.customer_id WHERE t2.channel_code  =  'Email'
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: What is the name of the customer that made the order with the largest quantity?
SQL: SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id WHERE t3.order_quantity  =  ( SELECT max(order_quantity) FROM order_items)
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Find the name of the customer who made the order of the largest amount of goods.
SQL: SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id WHERE t3.order_quantity  =  ( SELECT max(order_quantity) FROM order_items)
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: What is the name of the customer that has purchased the most items?
SQL: SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) DESC LIMIT 1
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Give me the name of the customer who ordered the most items in total.
SQL: SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) DESC LIMIT 1
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: What is the payment method of the customer that has purchased the least quantity of items?
SQL: SELECT t1.payment_method FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) LIMIT 1
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Tell me the payment method used by the customer who ordered the least amount of goods in total.
SQL: SELECT t1.payment_method FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id GROUP BY t1.customer_name ORDER BY sum(t3.order_quantity) LIMIT 1
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: How many types of products have Rodrick Heaney bought in total?
SQL: SELECT count(DISTINCT t3.product_id) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id WHERE t1.customer_name  =  "Rodrick Heaney"
-- Language PostgreSQL
        -- Tables: 
             -- Table: addresses 
columns : [['address id', 'number'], ['address content', 'text'], ['city', 'text'], ['zip postcode', 'text'], ['state province county', 'text'], ['country', 'text'], ['other address details', 'text']]

 -- Table: products 
columns : [['product id', 'number'], ['product details', 'text']]

 -- Table: customers 
columns : [['customer id', 'number'], ['payment method', 'text'], ['customer name', 'text'], ['date became customer', 'time'], ['other customer details', 'text']]

 -- Table: customer addresses 
columns : [['customer id', 'number'], ['address id', 'number'], ['date address from', 'time'], ['address type', 'text'], ['date address to', 'time']]

 -- Table: customer contact channels 
columns : [['customer id', 'number'], ['channel code', 'text'], ['active from date', 'time'], ['active to date', 'time'], ['contact number', 'text']]

 -- Table: customer orders 
columns : [['order id', 'number'], ['customer id', 'number'], ['order status', 'text'], ['order date', 'time'], ['order details', 'text']]

 -- Table: order items 
columns : [['order id', 'number'], ['product id', 'number'], ['order quantity', 'text']]

You are a SQL code translator. You have been given the Table data above. Your role is to translate natural language to PostgreSQL. 
You should not select columns that are not part of the tables provided to you. Think step by step.
Your only output should be SQL code. Do not include any other text. Only SQL code.



Question: Find the number of distinct products Rodrick Heaney has bought so far.
SQL: SELECT count(DISTINCT t3.product_id) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id  =  t2.customer_id JOIN order_items AS t3 ON t2.order_id  =  t3.order_id WHERE t1.customer_name  =  "Rodrick Heaney"