System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.users ( user_id.text, username.text, email.text, password_hash.text, full_name.text, profile_picture_url.text, bio.text, location.text, created_at.timestamp, updated_at.timestamp, is_verified.boolean )
CREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )
CREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )
CREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )
CREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )
CREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )
CREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )
CREATE TABLE social_media.user_settings ( setting_id.text, user_id.text, theme.text, email_notifications_enabled.boolean, push_notifications_enabled.boolean, private_profile.boolean, updated_at.timestamp )

[User] List the username and full name of all users who have set their profile to private.

[Assistant] SELECT u.username, u.full_name FROM social_media.users u JOIN social_media.user_settings us ON u.user_id = us.user_id WHERE us.private_profile = TRUE;

[User] Now, narrow down the list to only show those users who also have email notifications enabled.

[Assistant] SELECT u.username, u.full_name FROM social_media.users u JOIN social_media.user_settings us ON u.user_id = us.user_id WHERE us.private_profile = TRUE AND us.email_notifications_enabled = TRUE;

[User] Show me a list of all notifications that are related to comments. Include the notification ID, the recipient user ID, and the target entity ID, which corresponds to the comment ID.

[Assistant] SELECT notification_id, recipient_user_id, target_entity_id FROM social_media.notifications WHERE target_entity_type = 'comment';

[User] Please expand that list to include the username of the notification recipient and the content of the comment that the notification is about.

[Assistant] SELECT n.notification_id, u.username, c.content FROM social_media.notifications n JOIN social_media.users u ON n.recipient_user_id = u.user_id JOIN social_media.comments c ON n.target_entity_id = c.comment_id WHERE n.target_entity_type = 'comment';

[User] Okay, filter this down to only show notifications where the comment content is not empty, and the notification type is either 'like' or 'comment'.

[Assistant] SELECT n.notification_id, u.username, c.content FROM social_media.notifications n JOIN social_media.users u ON n.recipient_user_id = u.user_id JOIN social_media.comments c ON n.target_entity_id = c.comment_id WHERE n.target_entity_type = 'comment' AND (c.content IS NOT NULL AND c.content != '') AND n.notification_type IN ('like', 'comment');

[User] Show me the usernames and the group names of group chats where each user has posted at least one post containing a hashtag.

[Assistant]
SELECT u.username, c.group_name
FROM social_media.users u
JOIN social_media.posts p ON u.user_id = p.user_id
JOIN social_media.post_hashtags ph ON p.post_id = ph.post_id
JOIN social_media.conversations c ON p.user_id = u.user_id AND c.is_group_chat = TRUE
GROUP BY u.username, c.group_name;

[User] Can you also show when each group chat was created?

[Assistant]
SELECT u.username, c.group_name, c.created_at
FROM social_media.users u
JOIN social_media.posts p ON u.user_id = p.user_id
JOIN social_media.post_hashtags ph ON p.post_id = ph.post_id
JOIN social_media.conversations c ON p.user_id = u.user_id AND c.is_group_chat = TRUE
GROUP BY u.username, c.group_name, c.created_at;

[User] List users who have email notifications disabled.

[Assistant] SELECT T1.username FROM social_media.users AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = false

[User] Also show when their settings were last updated.

[Assistant] SELECT T1.username, T2.updated_at FROM social_media.users AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = false

[User] Show me the content of comments and the username of the author of the post the comment is on.

[Assistant] SELECT T1.content, T3.username FROM social_media.comments AS T1 JOIN social_media.posts AS T2 ON T1.post_id = T2.post_id JOIN social_media.users AS T3 ON T2.user_id = T3.user_id

[User] Only include comments made after '2024-01-01'.

[Assistant] SELECT T1.content, T3.username FROM social_media.comments AS T1 JOIN social_media.posts AS T2 ON T1.post_id = T2.post_id JOIN social_media.users AS T3 ON T2.user_id = T3.user_id WHERE T1.created_at > '2024-01-01'

[User] Actually, also show the post content and limit to the top 10 most recent comments.

[Assistant] SELECT T1.content, T3.username, T2.content FROM social_media.comments AS T1 JOIN social_media.posts AS T2 ON T1.post_id = T2.post_id JOIN social_media.users AS T3 ON T2.user_id = T3.user_id WHERE T1.created_at > '2024-01-01' ORDER BY T1.created_at DESC LIMIT 10


System:
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE train_station_management.stations ( station_id text, station_name text, city text, state_province text, country_code text, address text, timezone text, number_of_platforms integer, created_at timestamp, last_updated_at timestamp )

[User] What is the schedule of trains arriving at station with ID 'ST789' tomorrow?

[Assistant] I'm sorry, but I can't provide the train schedule for station ID 'ST789' as this information is not available in the current database. The table only contains details about station attributes such as name, location, and number of platforms. For train schedules, please refer to the relevant train service provider or timetable database.

[User] What is the ticket price for a journey on train number T4321?

[Assistant] I'm sorry, but I don't have access to information about ticket prices for specific trains. The data I have is limited to train details such as model, manufacturer, capacity, and maintenance schedules. For ticket pricing, please consult the ticketing office or the official website.

[User] What is the total revenue generated by ticket sales at the station with ID 'ST101' for the past month?

[Assistant] I'm sorry, but I can't provide information on the revenue generated by ticket sales as this data is not available in the current database table. The table only contains details about station information such as name, location, and platform count. If you have another question or need assistance with something else related to the station data, I'm happy to help.

[User] What is the maintenance schedule for the platforms at the station with ID 'ST234' for the next month?

[Assistant] I'm sorry, but I don't have access to the maintenance schedule for the platforms at any station. The data I have only includes basic station information such as station ID, name, location, and number of platforms. For maintenance schedules, you may need to contact the station management or relevant authorities.

[User] What is the detailed repair history for train number T5678?

[Assistant] I'm sorry, but I can't provide the detailed repair history for train number T5678 as this information is not available in the current database table. The table only includes basic information such as train ID, model, manufacturer, capacity, status, and maintenance dates. For repair history, you may need to consult a different database or department.


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )

[User] List the number of bookings for each day.

[Assistant]
SELECT DATE(booking_time) AS booking_date, COUNT(*) AS booking_count
FROM transportation.bookings
GROUP BY DATE(booking_time);

[User] Now only include days where booking_count > 10.

[Assistant]
SELECT DATE(booking_time) AS booking_date, COUNT(*) AS booking_count
FROM transportation.bookings
GROUP BY DATE(booking_time)
HAVING COUNT(*) > 10;

[User] Also include the total fare collected for those days.

[Assistant]
SELECT DATE(booking_time) AS booking_date,
       COUNT(*) AS booking_count,
       SUM(fare) AS total_fare
FROM transportation.bookings
GROUP BY DATE(booking_time)
HAVING COUNT(*) > 10;

[User] Find all pairs of bookings that share the same payment_transaction_id.

[Assistant]
SELECT b1.booking_id AS booking_id_1, b2.booking_id AS booking_id_2, b1.payment_transaction_id
FROM transportation.bookings b1
JOIN transportation.bookings b2
  ON b1.payment_transaction_id = b2.payment_transaction_id
 AND b1.booking_id < b2.booking_id;

[User] Now limit the results to pairs where both bookings have status 'Completed'.

[Assistant]
SELECT b1.booking_id AS booking_id_1, b2.booking_id AS booking_id_2, b1.payment_transaction_id
FROM transportation.bookings b1
JOIN transportation.bookings b2
  ON b1.payment_transaction_id = b2.payment_transaction_id
 AND b1.booking_id < b2.booking_id
WHERE b1.status = 'Completed'
  AND b2.status = 'Completed';

[User] What are the average and maximum fare amounts for each booking status?

[Assistant]
SELECT status, AVG(fare) AS avg_fare, MAX(fare) AS max_fare
FROM transportation.bookings
GROUP BY status;

[User] Only include statuses where the average fare is greater than 50.

[Assistant]
SELECT status, AVG(fare) AS avg_fare, MAX(fare) AS max_fare
FROM transportation.bookings
GROUP BY status
HAVING AVG(fare) > 50;

[User] List pairs of bookings made for the same trip, showing booking IDs and their booking_time.

[Assistant]
SELECT b1.booking_id AS booking1,
       b2.booking_id AS booking2,
       b1.trip_id,
       b1.booking_time AS time1,
       b2.booking_time AS time2
FROM transportation.bookings b1
JOIN transportation.bookings b2
  ON b1.trip_id = b2.trip_id
  AND b1.booking_id < b2.booking_id;

[User] Actually, only include pairs where the time difference between bookings is less than 2 hours.

[Assistant]
SELECT b1.booking_id AS booking1,
       b2.booking_id AS booking2,
       b1.trip_id,
       b1.booking_time AS time1,
       b2.booking_time AS time2
FROM transportation.bookings b1
JOIN transportation.bookings b2
  ON b1.trip_id = b2.trip_id
  AND b1.booking_id < b2.booking_id
WHERE ABS(EXTRACT(EPOCH FROM (b2.booking_time - b1.booking_time))) < 2 * 3600;

[User] Also calculate the difference in minutes between the two booking_time values as diff_minutes.

[Assistant]
SELECT b1.booking_id AS booking1,
       b2.booking_id AS booking2,
       b1.trip_id,
       b1.booking_time AS time1,
       b2.booking_time AS time2,
       ROUND(ABS(EXTRACT(EPOCH FROM (b2.booking_time - b1.booking_time))) / 60, 2) AS diff_minutes
FROM transportation.bookings b1
JOIN transportation.bookings b2
  ON b1.trip_id = b2.trip_id
  AND b1.booking_id < b2.booking_id
WHERE ABS(EXTRACT(EPOCH FROM (b2.booking_time - b1.booking_time))) < 2 * 3600;

[User] List each booking with its previous booking time for the same passenger.

[Assistant]
SELECT b.booking_id,
       b.passenger_id,
       b.booking_time,
       LAG(b.booking_time) OVER (PARTITION BY b.passenger_id ORDER BY b.booking_time) AS previous_booking_time
FROM transportation.bookings b;

[User] I only want records where the gap between bookings is more than 7 days.

[Assistant]
SELECT booking_id,
       passenger_id,
       booking_time,
       previous_booking_time
FROM (
  SELECT booking_id,
         passenger_id,
         booking_time,
         LAG(booking_time) OVER (PARTITION BY passenger_id ORDER BY booking_time) AS previous_booking_time
  FROM transportation.bookings
) t
WHERE previous_booking_time IS NOT NULL
  AND booking_time - previous_booking_time > INTERVAL '7 days';

[User] Also include the total number of bookings for each passenger.

[Assistant]
SELECT booking_id,
       passenger_id,
       booking_time,
       previous_booking_time,
       COUNT(*) OVER (PARTITION BY passenger_id) AS total_bookings
FROM (
  SELECT booking_id,
         passenger_id,
         booking_time,
         LAG(booking_time) OVER (PARTITION BY passenger_id ORDER BY booking_time) AS previous_booking_time
  FROM transportation.bookings
) t
WHERE previous_booking_time IS NOT NULL
  AND booking_time - previous_booking_time > INTERVAL '7 days';


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )
CREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, top_3_coins text, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, market_cap double precision, volume_24h double precision, trend_rank bigint, token_num bigint )
CREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_6h double precision, price_change_percentage_24h double precision, makers_24h double precision, volume_24h double precision, liquidity double precision, market_cap double precision, trend_rank bigint )
CREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL, chain character varying(128) NOT NULL, address character varying(128) NOT NULL, exchange character varying(512) NOT NULL, token_address character varying(128) NOT NULL, token_symbol character varying(512), balance numeric(38,10), usd_value numeric(38,14), price double precision )
CREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )

[User] Which projects had fundraising rounds named 'Series A' in 2022, and what are their token symbols and current token prices from DEX pools?

[Assistant]
SELECT p.project_name, p.rounds_name, d.token_symbol, d.price
FROM project_fundraising_record p
JOIN token_dexpool_info d ON LOWER(p.project_name) = LOWER(d.token_name)
WHERE p.rounds_name = 'Series A' AND p.investment_date LIKE '2022%';

[User] Can you also include the chain of each token and order the results by token price descending?

[Assistant]
SELECT p.project_name, p.rounds_name, d.token_symbol, d.chain, d.price
FROM project_fundraising_record p
JOIN token_dexpool_info d ON LOWER(p.project_name) = LOWER(d.token_name)
WHERE p.rounds_name = 'Series A' AND p.investment_date LIKE '2022%'
ORDER BY d.price DESC;

[User] I only want to see projects where the fundraising amount exceeded $10,000,000.

[Assistant]
SELECT p.project_name, p.rounds_name, d.token_symbol, d.chain, d.price
FROM project_fundraising_record p
JOIN token_dexpool_info d ON LOWER(p.project_name) = LOWER(d.token_name)
WHERE p.rounds_name = 'Series A' AND p.investment_date LIKE '2022%'
  AND p.investment_value > 10000000
ORDER BY d.price DESC;

[User] I got empty results, maybe the join with project_name and token_name is too strict. Can you try joining where either project_name equals token_name or project_name is contained in token_name, in a case-insensitive way?

[Assistant]
SELECT p.project_name, p.rounds_name, d.token_symbol, d.chain, d.price
FROM project_fundraising_record p
JOIN token_dexpool_info d
  ON LOWER(p.project_name) = LOWER(d.token_name)
    OR LOWER(d.token_name) LIKE CONCAT('%', LOWER(p.project_name), '%')
WHERE p.rounds_name = 'Series A' AND p.investment_date LIKE '2022%'
  AND p.investment_value > 10000000
ORDER BY d.price DESC;

[User] For each narrative, show its name and the total market cap of all related tokens based on DEX pool data.

[Assistant]
SELECT n.narrative, SUM(d.market_cap) AS total_market_cap
FROM narrative_info n
JOIN token_dexpool_info d ON n.top_3_coins LIKE CONCAT('%', d.token_symbol, '%')
GROUP BY n.narrative;

[User] Could you also include the number of tokens per narrative as a column in the result?

[Assistant]
SELECT n.narrative, COUNT(DISTINCT d.token_symbol) AS token_count, SUM(d.market_cap) AS total_market_cap
FROM narrative_info n
JOIN token_dexpool_info d ON n.top_3_coins LIKE CONCAT('%', d.token_symbol, '%')
GROUP BY n.narrative;

[User] I want to filter out narratives where the total market cap is less than 100 million USD.

[Assistant]
SELECT n.narrative, COUNT(DISTINCT d.token_symbol) AS token_count, SUM(d.market_cap) AS total_market_cap
FROM narrative_info n
JOIN token_dexpool_info d ON n.top_3_coins LIKE CONCAT('%', d.token_symbol, '%')
GROUP BY n.narrative
HAVING SUM(d.market_cap) >= 100000000;

[User] List tokens on the 'Polygon' chain held by CEX addresses. Show token_symbol and total USD value held.

[Assistant]
SELECT token_symbol, SUM(usd_value) AS total_usd_value
FROM cex_token_balance
WHERE chain = 'Polygon'
GROUP BY token_symbol;

[User] Include the smart money average price (avg_price) for each token.

[Assistant]
SELECT c.token_symbol, SUM(c.usd_value) AS total_usd_value, AVG(i.avg_price) AS avg_price
FROM cex_token_balance c
LEFT JOIN smart_money_token_inflow i
  ON c.token_symbol = i.token_symbol
  AND c.chain = i.chain
  AND i.type = 1
WHERE c.chain = 'Polygon'
GROUP BY c.token_symbol;

[User] Filter to only include tokens with total USD value above 1000000.

[Assistant]
SELECT c.token_symbol, SUM(c.usd_value) AS total_usd_value, AVG(i.avg_price) AS avg_price
FROM cex_token_balance c
LEFT JOIN smart_money_token_inflow i
  ON c.token_symbol = i.token_symbol
  AND c.chain = i.chain
  AND i.type = 1
WHERE c.chain = 'Polygon'
GROUP BY c.token_symbol
HAVING SUM(c.usd_value) > 1000000;

[User] Order by total USD value descending and limit to top 5 tokens.

[Assistant]
SELECT c.token_symbol, SUM(c.usd_value) AS total_usd_value, AVG(i.avg_price) AS avg_price
FROM cex_token_balance c
LEFT JOIN smart_money_token_inflow i
  ON c.token_symbol = i.token_symbol
  AND c.chain = i.chain
  AND i.type = 1
WHERE c.chain = 'Polygon'
GROUP BY c.token_symbol
HAVING SUM(c.usd_value) > 1000000
ORDER BY total_usd_value DESC
LIMIT 5;

[User] What is the average project valuation for each round name in 2023?

[Assistant]
SELECT rounds_name, AVG(valuation) AS avg_valuation
FROM project_fundraising_record
WHERE investment_date LIKE '2023-%'
GROUP BY rounds_name;

[User] Only include rounds where the average valuation is above 50000000.

[Assistant]
SELECT rounds_name, AVG(valuation) AS avg_valuation
FROM project_fundraising_record
WHERE investment_date LIKE '2023-%'
GROUP BY rounds_name
HAVING AVG(valuation) > 50000000;

[User] List all tokens on the 'Ethereum' chain with DEX 24h volume over 1000000. Show token_symbol, price, and volume_24h.

[Assistant]
SELECT token_symbol, price, volume_24h
FROM token_dexpool_info
WHERE chain = 'Ethereum' AND volume_24h > 1000000;

[User] Also show the total USD inflow from smart money (type=1) for each token.

[Assistant]
SELECT t.token_symbol, t.price, t.volume_24h, COALESCE(SUM(i.usd_value),0) AS total_usd_inflow
FROM token_dexpool_info t
LEFT JOIN smart_money_token_inflow i
  ON t.token_symbol = i.token_symbol
  AND t.chain = i.chain
  AND i.type = 1
WHERE t.chain = 'Ethereum' AND t.volume_24h > 1000000
GROUP BY t.token_symbol, t.price, t.volume_24h;

[User] Filter to only include tokens with total USD inflow greater than 500000.

[Assistant]
SELECT t.token_symbol, t.price, t.volume_24h, COALESCE(SUM(i.usd_value),0) AS total_usd_inflow
FROM token_dexpool_info t
LEFT JOIN smart_money_token_inflow i
  ON t.token_symbol = i.token_symbol
  AND t.chain = i.chain
  AND i.type = 1
WHERE t.chain = 'Ethereum' AND t.volume_24h > 1000000
GROUP BY t.token_symbol, t.price, t.volume_24h
HAVING COALESCE(SUM(i.usd_value),0) > 500000;

[User] Order the results by total USD inflow descending and limit to top 5.

[Assistant]
SELECT t.token_symbol, t.price, t.volume_24h, COALESCE(SUM(i.usd_value),0) AS total_usd_inflow
FROM token_dexpool_info t
LEFT JOIN smart_money_token_inflow i
  ON t.token_symbol = i.token_symbol
  AND t.chain = i.chain
  AND i.type = 1
WHERE t.chain = 'Ethereum' AND t.volume_24h > 1000000
GROUP BY t.token_symbol, t.price, t.volume_24h
HAVING COALESCE(SUM(i.usd_value),0) > 500000
ORDER BY total_usd_inflow DESC
LIMIT 5;