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 gaming_technology.in_game_items ( item_id uuid PRIMARY KEY, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )

[User] Can you list the number of items for each rarity in the system?

[Assistant]
SELECT rarity, COUNT(*) AS item_count
FROM gaming_technology.in_game_items
GROUP BY rarity;

[User] Please only show rarities with at least 3 items.

[Assistant]
SELECT rarity, COUNT(*) AS item_count
FROM gaming_technology.in_game_items
GROUP BY rarity
HAVING COUNT(*) >= 3;

[User] Can you also display the minimum, maximum, and average cost amount for each rarity?

[Assistant]
SELECT rarity, COUNT(*) AS item_count, MIN(cost_amount) AS min_cost, MAX(cost_amount) AS max_cost, AVG(cost_amount) AS avg_cost
FROM gaming_technology.in_game_items
GROUP BY rarity
HAVING COUNT(*) >= 3;


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 trading_platform.trades ( trade_id text, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )
CREATE TABLE trading_platform.utxos ( utxo_id text, transaction_id text, output_index integer, address text, amount numeric, spent boolean )
CREATE TABLE trading_platform.metadata ( metadata_id text, asset_id text, key text, value text )
CREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )

[User] Show each user's total count of notifications and, for each, how many of them have been read.

[Assistant]
SELECT user_id, COUNT(*) AS total_notifications, COUNT(read_at) AS notifications_read
FROM trading_platform.notifications
GROUP BY user_id;

[User] Please only include users who have more than 2 notifications.

[Assistant]
SELECT user_id, COUNT(*) AS total_notifications, COUNT(read_at) AS notifications_read
FROM trading_platform.notifications
GROUP BY user_id
HAVING COUNT(*) > 2;

[User] Now, for these users, show the most recent sent_at date for any notification.

[Assistant]
SELECT user_id, COUNT(*) AS total_notifications, COUNT(read_at) AS notifications_read, MAX(sent_at) AS last_notification_sent_at
FROM trading_platform.notifications
GROUP BY user_id
HAVING COUNT(*) > 2;

[User] Also, display only those users who have at least one read notification.

[Assistant]
SELECT user_id, COUNT(*) AS total_notifications, COUNT(read_at) AS notifications_read, MAX(sent_at) AS last_notification_sent_at
FROM trading_platform.notifications
GROUP BY user_id
HAVING COUNT(*) > 2 AND COUNT(read_at) > 0;


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 hospitality_technology.properties ( property_id.text, property_name.text, address_line1.text, address_line2.text, city.text, state_province.text, postal_code.text, country_code.text, phone_number.text, email_address.text, property_type.text, star_rating.numeric, timezone.text, manager_staff_id.text, created_at.timestamp, updated_at.timestamp )
CREATE TABLE hospitality_technology.rooms ( room_id.text, property_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, current_condition.text, last_cleaned_at.timestamp )
CREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )
CREATE TABLE hospitality_technology.service_orders ( order_id.text, reservation_id.text, guest_id.text, service_id.text, staff_id_ordered.text, staff_id_delivered.text, order_timestamp.timestamp, delivery_timestamp.timestamp, quantity.integer, unit_price.numeric, total_price.numeric, status.text, notes.text, bill_id.text )
CREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )
CREATE TABLE hospitality_technology.reviews ( review_id.text, property_id.text, reservation_id.text, guest_id.text, rating_overall.integer, rating_cleanliness.integer, rating_service.integer, rating_location.integer, rating_value.integer, comment.text, review_source.text, review_date.timestamp, is_public.boolean, staff_response.text, response_staff_id.text, response_date.timestamp )

[User] List all service orders for spa services in the last month, including the guest ID and total price.

[Assistant] SELECT order_id, guest_id, total_price FROM hospitality_technology.service_orders WHERE service_id LIKE 'SPA%' AND order_timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);

[User] Now, include only orders with a total price over $100 and order them by total price in descending order.

[Assistant] SELECT order_id, guest_id, total_price FROM hospitality_technology.service_orders WHERE service_id LIKE 'SPA%' AND order_timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND total_price > 100 ORDER BY total_price DESC;

[User] The query is missing the property ID. Can you include that as well?

[Assistant] SELECT so.order_id, so.guest_id, so.total_price, r.property_id FROM hospitality_technology.service_orders so JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id WHERE so.service_id LIKE 'SPA%' AND so.order_timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND so.total_price > 100 ORDER BY so.total_price DESC;

[User] Actually, I need to see the service description too, and order by guest ID.

[Assistant] SELECT so.order_id, so.guest_id, so.total_price, r.property_id, s.description FROM hospitality_technology.service_orders so JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id JOIN hospitality_technology.services s ON so.service_id = s.service_id WHERE so.service_id LIKE 'SPA%' AND so.order_timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND so.total_price > 100 ORDER BY so.guest_id;


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.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 user ID, theme, and updated_at for users who have updated their settings in the last 90 days and have their theme set to 'dark'.

[Assistant] SELECT user_id, theme, updated_at FROM social_media.user_settings WHERE updated_at >= NOW() - INTERVAL '90 days' AND theme = 'dark';

[User] Refine the list to only show users who have also disabled push notifications.

[Assistant] SELECT user_id, theme, updated_at FROM social_media.user_settings WHERE updated_at >= NOW() - INTERVAL '90 days' AND theme = 'dark' AND push_notifications_enabled = FALSE;


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 insurance.agents ( agent_id.text, first_name.text, last_name.text, agency_name.text, license_number.text, license_state.text, contact_email.text, contact_phone.text, hire_date.date, termination_date.date, status.text, commission_rate.numeric, manager_id.text )

[User] List each agent along with their manager's contact_email. Include agent_id, first_name, last_name, manager_id, and manager's contact_email.

[Assistant]
SELECT a.agent_id,
       a.first_name,
       a.last_name,
       a.manager_id,
       m.contact_email AS manager_contact_email
FROM insurance.agents a
LEFT JOIN insurance.agents m
  ON a.manager_id = m.agent_id;

[User] Actually, only include records where the manager is currently active.

[Assistant]
SELECT a.agent_id,
       a.first_name,
       a.last_name,
       a.manager_id,
       m.contact_email AS manager_contact_email
FROM insurance.agents a
LEFT JOIN insurance.agents m
  ON a.manager_id = m.agent_id
WHERE m.status = 'active';