Dataset Viewer
Auto-converted to Parquet Duplicate
system
stringlengths
3.56k
8.71k
conversations
listlengths
4
26
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 character varying(64) NOT NULL, -- unique identifier for the user username character varying(50) NOT NULL UNIQUE, -- user's unique handle email character varying(128) NOT NULL UNIQUE, -- user's email address password_hash text NOT NULL, -- hashed password full_name character varying(100), -- user's full name profile_picture_url text, -- URL to the profile picture bio text, -- short user biography location character varying(100), -- user's location created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update is_verified boolean NOT NULL DEFAULT false, -- verification status PRIMARY KEY (user_id) ) CREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used PRIMARY KEY (hashtag_id) ) CREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, -- unique identifier for the message conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id) sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id) content text, -- textual content of the message media_url text, -- URL to attached media (image/video) media_type character varying(20), -- type of media ('image', 'video', null) sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent read_at timestamp, -- timestamp when message was read by recipient(s) PRIMARY KEY (message_id) ) CREATE TABLE social_media.conversation_participants ( participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id) user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id) joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation last_read_at timestamp, -- timestamp indicating up to when the user has read messages PRIMARY KEY (participant_id), CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times ) CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, -- unique identifier for the notification recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id) sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications) notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message') target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id) target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created read_at timestamp, -- timestamp notification was marked as read PRIMARY KEY (notification_id) ) CREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id) theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark') email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications private_profile boolean DEFAULT false, -- is the user profile private updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change PRIMARY KEY (setting_id) ) ##Table Structure CREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, room_number character varying(10) NOT NULL, room_type_id character varying(64) NOT NULL, floor integer, status character varying(50) NOT NULL, is_smoking boolean NOT NULL DEFAULT false, features text, current_condition text, last_cleaned_at timestamp with time zone, PRIMARY KEY (room_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) ) CREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) ) ##Table Structure CREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text ) CREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) ) CREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text ) CREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text ) CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id.text, policy_id.text, customer_id.text, first_name.text, last_name.text, relationship.text, percentage_share.numeric, contact_info.text, added_at.timestamp ) ##Table Structure CREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )
[ { "role": "user", "content": "List usernames and bio information for users who have set a non-empty bio in their profile." }, { "role": "assistant", "content": "SELECT username, bio\nFROM social_media.users\nWHERE bio IS NOT NULL AND TRIM(bio) <> '';" }, { "role": "user", "content": "Show me all reservations with their reservation_id, room_number, room status, and check_in_date." }, { "role": "assistant", "content": "SELECT r.reservation_id,\n rm.room_number,\n rm.status AS room_status,\n r.check_in_date\nFROM hospitality_technology.reservations r\nLEFT JOIN hospitality_technology.rooms rm\n ON r.room_id = rm.room_id;" }, { "role": "user", "content": "Count the number of claim documents for each distinct MIME type." }, { "role": "assistant", "content": "SELECT mime_type, COUNT(*) FROM insurance.claim_documents GROUP BY mime_type" }, { "role": "user", "content": "Find all pairs of different insurance records that share the same group_number, and show group_number, the patient_insurance_id of both records, and their corresponding patient_ids." }, { "role": "assistant", "content": "SELECT a.group_number,\n a.patient_insurance_id AS pi_id1,\n a.patient_id AS patient1_id,\n b.patient_insurance_id AS pi_id2,\n b.patient_id AS patient2_id\nFROM healthcare.patient_insurance a\nJOIN healthcare.patient_insurance b\n ON a.group_number = b.group_number\n AND a.patient_insurance_id < b.patient_insurance_id\nWHERE a.group_number IS NOT NULL;" } ]
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.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) ) CREATE TABLE trading_platform.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp ) CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp ) CREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, -- unique identifier for the trade order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade buyer_id character varying(64) NOT NULL, -- identifier of the buyer seller_id character varying(64) NOT NULL, -- identifier of the seller asset_id character varying(64) NOT NULL, -- identifier of the asset being traded quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade price numeric(38,14) NOT NULL, -- price per unit of the asset traded_at timestamp NOT NULL, -- time when the trade was executed PRIMARY KEY (trade_id) ) CREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) ) CREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) ) CREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp ) CREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text ) CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit user_id character varying(64) NOT NULL, -- identifier of the user being audited status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected) reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed PRIMARY KEY (kyc_audit_id) ) CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp ) ##Table Structure CREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) ) ##Table Structure CREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean ) CREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp ) ##Table Structure CREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, -- full primary residential address contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, -- when the citizen profile was created is_verified boolean DEFAULT false, -- whether identity has been officially verified PRIMARY KEY (citizen_id) ) ##Table Structure CREATE TABLE web3.tokens ( token_id character varying(64) NOT NULL, -- unique identifier for the token contract_address character varying(128) NOT NULL, -- address of the token contract token_name character varying(128) NOT NULL, -- name of the token token_symbol character varying(32) NOT NULL, -- symbol of the token decimals integer NOT NULL, -- number of decimals for the token total_supply numeric(38,14) NOT NULL, -- total supply of the token PRIMARY KEY (token_id) ) ##Table Structure CREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp ) ##Table Structure CREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) ) ##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 )
[ { "role": "user", "content": "For each peer port, count how many peers have used that port." }, { "role": "assistant", "content": "SELECT port,\n COUNT(*) AS peer_count\nFROM trading_platform.peers\nGROUP BY port;" }, { "role": "user", "content": "Give me the count of policies grouped by their status." }, { "role": "assistant", "content": "SELECT status,\n COUNT(*) AS policy_count\nFROM insurance.policies\nGROUP BY status;" }, { "role": "user", "content": "List all invoices that were paid within 7 days of their issue date. Show invoice number, issue date, payment date, and total amount." }, { "role": "assistant", "content": "SELECT invoice_number, issue_date, payment_date, total_amount FROM legal_services.invoices WHERE status = 'Paid' AND payment_date IS NOT NULL AND (payment_date::DATE - issue_date) <= 7;" }, { "role": "user", "content": "Provide a count of citizens registered per calendar year." }, { "role": "assistant", "content": "SELECT CAST(EXTRACT(YEAR FROM registration_date) AS INTEGER) AS registration_year, COUNT(*) AS citizen_count FROM government_services.citizens GROUP BY 1 ORDER BY 1;" }, { "role": "user", "content": "For each token, show its token_id, decimals, and the average total_supply of all tokens with the same decimals." }, { "role": "assistant", "content": "SELECT t.token_id,\n t.decimals,\n avg_data.avg_total_supply\nFROM web3.tokens t\nJOIN (\n SELECT decimals,\n AVG(total_supply) AS avg_total_supply\n FROM web3.tokens\n GROUP BY decimals\n) AS avg_data\n ON t.decimals = avg_data.decimals;" }, { "role": "user", "content": "List each user along with the wallet_id of their first created wallet." }, { "role": "assistant", "content": "SELECT\n m.user_id,\n w.wallet_id AS first_wallet_id\nFROM (\n SELECT user_id, MIN(created_at) AS first_created_at\n FROM web3.wallets\n GROUP BY user_id\n) AS m\nJOIN web3.wallets AS w\n ON w.user_id = m.user_id\n AND w.created_at = m.first_created_at;" }, { "role": "user", "content": "For each event, display its event_id, the event_id of the previous event in the same transaction (if any), and the log_index of both events." }, { "role": "assistant", "content": "SELECT curr.event_id AS current_event_id,\n prev.event_id AS previous_event_id,\n curr.log_index AS current_log_index,\n prev.log_index AS previous_log_index,\n curr.transaction_id\nFROM web3.events curr\nLEFT JOIN web3.events prev\n ON curr.transaction_id = prev.transaction_id\n AND curr.log_index = prev.log_index + 1;" }, { "role": "user", "content": "List all users who signed up in 2024 and have not set a bio. Show their usernames, emails, and account creation dates." }, { "role": "assistant", "content": "SELECT username, email, created_at FROM social_media.users WHERE bio IS NULL AND EXTRACT(YEAR FROM created_at) = 2024;" } ]
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 healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp ) CREATE TABLE healthcare.appointments ( appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment patient_id character varying(64) NOT NULL, -- FK to patients table doctor_id character varying(64) NOT NULL, -- FK to doctors table appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment duration_minutes integer NOT NULL, -- expected duration in minutes reason text, -- reason for the visit status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show location_id character varying(64), -- FK to a potential locations/clinics table notes text, -- notes related to scheduling created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) ) CREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry patient_id character varying(64) NOT NULL, -- FK to patients table appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt) doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record) record_date timestamp with time zone NOT NULL, -- date the record/observation was made chief_complaint text, -- patient's primary reason for visit present_illness_history text, -- detailed history of the current issue past_medical_history text, -- relevant past conditions/surgeries physical_examination_notes text, -- findings from the physical exam assessment text, -- doctor's assessment/diagnosis summary treatment_plan text, -- planned course of action vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) ) CREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean ) CREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text ) CREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) ) CREATE TABLE healthcare.insurance_plans ( plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan plan_name character varying(200) NOT NULL, -- name of the insurance plan insurance_provider character varying(100) NOT NULL, -- name of the insurance company plan_type character varying(50), -- e.g., PPO, HMO, EPO contact_phone character varying(20), -- provider contact number website character varying(255), -- provider website PRIMARY KEY (plan_id) ) ##Table Structure CREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, -- full primary residential address contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, -- when the citizen profile was created is_verified boolean DEFAULT false, -- whether identity has been officially verified PRIMARY KEY (citizen_id) ) CREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text ) CREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text ) CREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) ) CREATE TABLE government_services.documents ( document_id.text, application_id.text, citizen_id.text, document_type.text, file_reference.text, upload_timestamp.timestamp, expiry_date.date, verification_status.text, verified_by_employee_id.text, verification_timestamp.timestamp ) CREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text ) CREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, -- unique identifier for the physical location agency_id character varying(64) NOT NULL, -- FK to agencies table location_name character varying(200), -- e.g., Downtown DMV Office address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, -- description of opening times contact_phone character varying(32), is_accessible boolean, -- accessibility information (e.g., wheelchair access) PRIMARY KEY (location_id) ) CREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text ) ##Table Structure CREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )
[ { "role": "user", "content": "List the plan_id, plan_name, and plan_type for all insurance plans where the insurance_provider is 'Humana'." }, { "role": "assistant", "content": "SELECT\n plan_id,\n plan_name,\n plan_type\nFROM healthcare.insurance_plans\nWHERE\n insurance_provider = 'Humana';" }, { "role": "user", "content": "Show each service's name along with the total number of appointments scheduled and the number of unique locations these appointments are scheduled at." }, { "role": "assistant", "content": "SELECT s.service_name, COUNT(a.application_id) AS appointment_count, COUNT(DISTINCT ap.location_id) AS unique_location_count\nFROM government_services.services s\nJOIN government_services.applications a ON s.service_id = a.service_id\nJOIN government_services.appointments ap ON a.application_id = ap.application_id\nGROUP BY s.service_name;" }, { "role": "user", "content": "I got an error: relation 'appointments' does not exist." }, { "role": "assistant", "content": "-- The appointments table is not present in the provided schema. If you want to count by another join, perhaps by documents or payments, please specify.\n-- Alternatively, do you want appointment information replaced with application submissions per service and their associated location from service_locations?\nSELECT s.service_name, COUNT(a.application_id) AS application_count, COUNT(DISTINCT sl.location_id) AS unique_location_count\nFROM government_services.services s\nJOIN government_services.applications a ON s.service_id = a.service_id\nJOIN government_services.service_locations sl ON s.agency_id = sl.agency_id\nGROUP BY s.service_name;" }, { "role": "user", "content": "Show only those services where application_count is greater than 50." }, { "role": "assistant", "content": "SELECT s.service_name, COUNT(a.application_id) AS application_count, COUNT(DISTINCT sl.location_id) AS unique_location_count\nFROM government_services.services s\nJOIN government_services.applications a ON s.service_id = a.service_id\nJOIN government_services.service_locations sl ON s.agency_id = sl.agency_id\nGROUP BY s.service_name\nHAVING COUNT(a.application_id) > 50;" }, { "role": "user", "content": "List all law firms that do not have a managing partner listed." }, { "role": "assistant", "content": "SELECT firm_name, phone, address, founded_date\nFROM legal_services.law_firms\nWHERE managing_partner_id IS NULL;" } ]
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.likes ( like_id character varying(64) NOT NULL, -- unique identifier for the like user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id) post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable) comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something ) CREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id) following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows ) CREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used PRIMARY KEY (hashtag_id) ) CREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, -- unique identifier for the message conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id) sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id) content text, -- textual content of the message media_url text, -- URL to attached media (image/video) media_type character varying(20), -- type of media ('image', 'video', null) sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent read_at timestamp, -- timestamp when message was read by recipient(s) PRIMARY KEY (message_id) ) CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated last_message_at timestamp, -- timestamp of the last message in the conversation is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message group_name character varying(100), -- name of the group chat (if applicable) PRIMARY KEY (conversation_id) ) CREATE TABLE social_media.conversation_participants ( participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id) user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id) joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation last_read_at timestamp, -- timestamp indicating up to when the user has read messages PRIMARY KEY (participant_id), CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times ) CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, -- unique identifier for the notification recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id) sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications) notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message') target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id) target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created read_at timestamp, -- timestamp notification was marked as read PRIMARY KEY (notification_id) ) CREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id) theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark') email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications private_profile boolean DEFAULT false, -- is the user profile private updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change PRIMARY KEY (setting_id) ) ##Table Structure CREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric ) CREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric ) CREATE TABLE cex_token_balance ( snapshot_time text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric ) CREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text ) CREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text ) ##Table Structure CREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, -- unique identifier for the document instance application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly) citizen_id character varying(64) NOT NULL, -- FK to citizens table document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path) upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected verified_by_employee_id character varying(64), -- FK to employees table verification_timestamp timestamp, PRIMARY KEY (document_id) ) ##Table Structure CREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )
[ { "role": "user", "content": "Count the total number of likes on posts versus likes on comments across the entire platform." }, { "role": "assistant", "content": "SELECT CASE WHEN post_id IS NOT NULL THEN 'post' ELSE 'comment' END AS like_target, COUNT(*) AS total_likes FROM social_media.likes GROUP BY like_target;" }, { "role": "user", "content": "For the 'DeFi' narrative, what is the average ROI and the total net inflow (usd_value where type=1) from smart money token inflow?" }, { "role": "assistant", "content": "SELECT AVG(sm.roi) AS avg_roi, SUM(smt.usd_value) AS total_net_inflow\nFROM smart_money_token_inflow smt\nJOIN smart_money_profit sm ON smt.chain = sm.chain\nWHERE smt.narrative = 'DeFi' AND smt.type = 1;" }, { "role": "user", "content": "Count the number of documents for each unique document type." }, { "role": "assistant", "content": "SELECT document_type, COUNT(*) AS document_count FROM government_services.documents GROUP BY document_type ORDER BY document_count DESC;" }, { "role": "user", "content": "Show me the first_name, last_name, and firm_id of all lawyers whose email domain is 'legalfirm.com'." }, { "role": "assistant", "content": "SELECT first_name,\n last_name,\n firm_id\nFROM legal_services.lawyers\nWHERE SPLIT_PART(email, '@', 2) = 'legalfirm.com';" } ]
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.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text ) CREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text ) CREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp ) ##Table Structure CREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer ) CREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL ) CREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL ) CREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer ) CREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text ) CREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer ) CREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text ) CREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer ) CREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL ) CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal ) CREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table) block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table) tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table) tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table) tick varchar NOT NULL, -- Token tick max_supply decimal(38,0) NOT NULL, -- Max supply lim decimal(38,0) NOT NULL, -- Limit of each mint wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint dec integer NOT NULL, -- Decimal for minimum divie creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table) ) CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar ) CREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL ) CREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar ) CREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar ) CREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text ) CREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, -- Block number containing the transaction block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription wallet_address varchar(42) NOT NULL, -- Address of owner total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height ) CREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar ) ##Table Structure CREATE TABLE blockchain.wallets ( wallet_id text, user_id text, address_id text, private_key text ) ##Table Structure CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )
[ { "role": "user", "content": "Count the number of trips for each route type." }, { "role": "assistant", "content": "SELECT R.type, COUNT(T.trip_id) FROM transportation.trips AS T JOIN transportation.routes AS R ON T.route_id = R.route_id GROUP BY R.type;" }, { "role": "user", "content": "List all ERC20 tokens where the price is between $1 and $10, including their names, symbols, and contract addresses." }, { "role": "assistant", "content": "SELECT tm.name, tm.symbol, tm.contract_address FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.contract_address WHERE tm.is_erc20 = 1 AND tpl.price BETWEEN 1 AND 10;" }, { "role": "user", "content": "I think there's an error in your query - the token_prices_latest table isn't in the schema. Can you modify it to use the token_balances table instead?" }, { "role": "assistant", "content": "SELECT tm.name, tm.symbol, tm.contract_address FROM token_metas tm JOIN token_balances tb ON tm.contract_address = tb.wallet_address WHERE tm.is_erc20 = 1 AND CAST(tb.amount AS decimal) BETWEEN 1 AND 10;" }, { "role": "user", "content": "That doesn't seem right either. Let's just get the basic ERC20 token information without price filtering for now." }, { "role": "assistant", "content": "SELECT name, symbol, contract_address FROM token_metas WHERE is_erc20 = 1 LIMIT 100;" }, { "role": "user", "content": "Show me the top 5 users with the most wallet addresses, along with the count of their wallets." }, { "role": "assistant", "content": "SELECT user_id, COUNT(wallet_id) AS wallet_count FROM blockchain.wallets WHERE user_id IS NOT NULL GROUP BY user_id ORDER BY wallet_count DESC LIMIT 5;" }, { "role": "user", "content": "Now include the earliest created wallet address for each of these top 5 users." }, { "role": "assistant", "content": "Note: The wallets table doesn't have a creation timestamp column. Without this information, we cannot determine the earliest created wallet. Please provide a table with creation timestamps if you need this analysis." }, { "role": "user", "content": "Then just show me these top 5 users with their wallet counts and the first wallet_id alphabetically for each user." }, { "role": "assistant", "content": "SELECT user_id, COUNT(wallet_id) AS wallet_count, MIN(wallet_id) AS first_wallet_id FROM blockchain.wallets WHERE user_id IS NOT NULL GROUP BY user_id ORDER BY wallet_count DESC LIMIT 5;" }, { "role": "user", "content": "Provide a breakdown of the total number of conversations, showing how many are group chats and how many are not. Also, show the count of conversations that have a recorded last message time." }, { "role": "assistant", "content": "SELECT COUNT(*) AS total_conversations, COUNT(CASE WHEN is_group_chat = true THEN 1 END) AS group_chat_count, COUNT(CASE WHEN is_group_chat = false THEN 1 END) AS private_chat_count, COUNT(last_message_at) AS conversations_with_messages_count FROM social_media.conversations;" } ]
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 government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text ) CREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, -- unique identifier for the document instance application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly) citizen_id character varying(64) NOT NULL, -- FK to citizens table document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path) upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected verified_by_employee_id character varying(64), -- FK to employees table verification_timestamp timestamp, PRIMARY KEY (document_id) ) CREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text ) CREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, -- unique identifier for the government employee agency_id character varying(64) NOT NULL, -- FK to agencies table first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, -- null if currently employed access_level character varying(50), -- Role or permission level manager_employee_id character varying(64), -- FK to self for reporting structure PRIMARY KEY (employee_id) ) CREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) ) CREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) ) ##Table Structure CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (comment_id) ) CREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) ) CREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) ) CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) ) CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) ) CREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) ) ##Table Structure CREATE TABLE legal_services.lawyers ( lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer first_name character varying(100) NOT NULL, -- lawyer's first name last_name character varying(100) NOT NULL, -- lawyer's last name bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number firm_id character varying(64), -- FK to law_firms table email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email phone character varying(32), -- lawyer's contact phone number specialization text, -- areas of legal expertise hire_date timestamp NOT NULL, -- date the lawyer was hired or joined is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner PRIMARY KEY (lawyer_id) ) ##Table Structure CREATE TABLE web3.contracts ( contract_id text, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text ) ##Table Structure CREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp ) ##Table Structure CREATE TABLE cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric ) ##Table Structure CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )
[ { "role": "user", "content": "For each type of entity a notification can be related to, how many notifications have been successfully sent?" }, { "role": "assistant", "content": "SELECT related_entity_type, COUNT(*) AS sent_notification_count FROM government_services.notifications WHERE status = 'Sent' GROUP BY related_entity_type;" }, { "role": "user", "content": "How many likes were given to comments in June 2024?" }, { "role": "assistant", "content": "SELECT COUNT(*) AS comment_likes_count\nFROM social_media.likes\nWHERE comment_id IS NOT NULL \n AND DATE_TRUNC('month', created_at) = '2024-06-01';" }, { "role": "user", "content": "How many lawyers who are partners were hired in each year? Show the hire year and the count." }, { "role": "assistant", "content": "SELECT strftime('%Y', hire_date) AS hire_year , count(lawyer_id) FROM legal_services.lawyers WHERE is_partner = true GROUP BY hire_year" }, { "role": "user", "content": "For each network, list the deployer address and the number of contracts they have deployed, ordered from most to least." }, { "role": "assistant", "content": "SELECT network_id, deployer_address, COUNT(*) AS deployed_contracts FROM web3.contracts GROUP BY network_id, deployer_address ORDER BY network_id, deployed_contracts DESC;" }, { "role": "user", "content": "What are the top 5 product types by average base premium, showing the product_type and average base_premium, ordered by average base_premium descending?" }, { "role": "assistant", "content": "SELECT product_type, AVG(base_premium) AS avg_premium FROM insurance.insurance_products GROUP BY product_type ORDER BY avg_premium DESC LIMIT 5;" }, { "role": "user", "content": "How many unique tokens are recorded for each chain in the latest snapshot in cex_token_balance?" }, { "role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n)\nSELECT \n chain, \n COUNT(DISTINCT token_symbol) AS unique_token_count\nFROM cex_token_balance c\nJOIN latest_snapshot l ON c.snapshot_time = l.max_time\nGROUP BY chain\nORDER BY unique_token_count DESC;" }, { "role": "user", "content": "Count the number of logs for each distinct action type." }, { "role": "assistant", "content": "SELECT action, COUNT(*) AS log_count FROM trading_platform.logs GROUP BY action;" } ]
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.wallets ( wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet address character varying(128) NOT NULL, -- address of the wallet private_key text NOT NULL, -- private key of the wallet created_at timestamp NOT NULL, -- time when the wallet was created PRIMARY KEY (wallet_id) ) CREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, -- unique identifier for the order user_id character varying(64) NOT NULL, -- identifier of the user placing the order wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order asset_id character varying(64) NOT NULL, -- identifier of the asset being traded order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell) quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order price numeric(38,14) NOT NULL, -- price per unit of the asset status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled) created_at timestamp NOT NULL, -- time when the order was created PRIMARY KEY (order_id) ) CREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, -- unique identifier for the asset name character varying(128) NOT NULL, -- name of the asset symbol character varying(32) NOT NULL, -- symbol of the asset type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock) PRIMARY KEY (asset_id) ) CREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO output_index integer NOT NULL, -- index of the output in the transaction address character varying(128) NOT NULL, -- address that can spend the UTXO amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO spent boolean NOT NULL, -- whether the UTXO has been spent PRIMARY KEY (utxo_id) ) CREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp name character varying(128) NOT NULL, -- name of the DApp description text NOT NULL, -- description of the DApp url character varying(256) NOT NULL, -- URL of the DApp PRIMARY KEY (dapp_id) ) CREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, -- unique identifier for the peer ip_address character varying(15) NOT NULL, -- IP address of the peer port integer NOT NULL, -- port number of the peer last_seen timestamp NOT NULL, -- last time the peer was active PRIMARY KEY (peer_id) ) CREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with key character varying(128) NOT NULL, -- key of the metadata value text NOT NULL, -- value of the metadata PRIMARY KEY (metadata_id) ) CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit user_id character varying(64) NOT NULL, -- identifier of the user being audited status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected) reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed PRIMARY KEY (kyc_audit_id) ) CREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, -- unique identifier for the notification user_id character varying(64) NOT NULL, -- identifier of the user receiving the notification message text NOT NULL, -- message of the notification sent_at timestamp NOT NULL, -- time when the notification was sent read_at timestamp, -- time when the notification was read PRIMARY KEY (notification_id) ) ##Table Structure CREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, -- unique identifier for the claim policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies) customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers) incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported description text NOT NULL, -- detailed description of the incident and claim estimated_loss numeric(15, 2), -- initial estimated cost of the loss status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled settlement_amount numeric(15, 2), -- final amount paid out settlement_date date, claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters) police_report_number character varying(100), PRIMARY KEY (claim_id) ) ##Table Structure CREATE TABLE legal_services.invoices ( invoice_id character varying(64) NOT NULL, invoice_number character varying(100) UNIQUE NOT NULL, client_id character varying(64) NOT NULL, case_id character varying(64), issue_date date NOT NULL, due_date date NOT NULL, total_amount numeric(12, 2) NOT NULL, amount_paid numeric(12, 2) DEFAULT 0.00, status character varying(50) NOT NULL, payment_date timestamp, notes text, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (invoice_id) ) ##Table Structure CREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean ) CREATE TABLE healthcare.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp ) ##Table Structure CREATE TABLE web3.token_transfers ( transfer_id text PRIMARY KEY, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index int )
[ { "role": "user", "content": "For each asset, calculate the total quantity and average price of orders that have status 'filled'." }, { "role": "assistant", "content": "SELECT o.asset_id,\n SUM(o.quantity) AS total_quantity,\n AVG(o.price) AS average_price\nFROM trading_platform.orders o\nWHERE o.status = 'filled'\nGROUP BY o.asset_id;" }, { "role": "user", "content": "Calculate the average number of days between when an incident occurred and when the claim was reported, but only for claims that were settled in the year 2023." }, { "role": "assistant", "content": "SELECT\n AVG(EXTRACT(EPOCH FROM (reported_date - incident_date)) / 86400.0)::numeric(10, 2)\nFROM\n insurance.claims\nWHERE\n settlement_date IS NOT NULL AND EXTRACT(YEAR FROM settlement_date) = 2023;" }, { "role": "user", "content": "What is the average number of days by which paid invoices were paid late? Calculate the average of (payment_date - due_date) for invoices with status 'Paid'." }, { "role": "assistant", "content": "SELECT AVG((payment_date::date - due_date)) AS average_late_days\nFROM legal_services.invoices\nWHERE status = 'Paid';" }, { "role": "user", "content": "Count the total number of chronic diagnoses for each code_type." }, { "role": "assistant", "content": "SELECT\n code_type,\n COUNT(*) AS chronic_diagnosis_count\nFROM healthcare.diagnoses\nWHERE is_chronic = TRUE\nGROUP BY code_type;" }, { "role": "user", "content": "Find all pairs of token transfers where one transfer's sender and recipient are swapped with another transfer's sender and recipient, showing both transfer IDs." }, { "role": "assistant", "content": "SELECT t1.from_address AS sender,\n t1.to_address AS recipient,\n t1.transfer_id AS transfer1_id,\n t2.transfer_id AS transfer2_id\nFROM web3.token_transfers t1\nJOIN web3.token_transfers t2\n ON t1.from_address = t2.to_address\n AND t1.to_address = t2.from_address\n AND t1.transfer_id < t2.transfer_id;" } ]
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 healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp ) CREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp ) CREATE TABLE healthcare.appointments ( appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment patient_id character varying(64) NOT NULL, -- FK to patients table doctor_id character varying(64) NOT NULL, -- FK to doctors table appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment duration_minutes integer NOT NULL, -- expected duration in minutes reason text, -- reason for the visit status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show location_id character varying(64), -- FK to a potential locations/clinics table notes text, -- notes related to scheduling created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) ) CREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp ) CREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) ) CREATE TABLE healthcare.medications ( medication_id character varying(64) NOT NULL, -- unique identifier for the medication type medication_name character varying(255) NOT NULL, -- common or brand name generic_name character varying(255), -- generic chemical name manufacturer character varying(100), -- drug manufacturer ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful) description text, -- description of the medication PRIMARY KEY (medication_id) ) CREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp ) CREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text ) ##Table Structure // Use Hashes for ticket details. Key format: ticket:<ticket_id> // HSET ticket:tkt_1a2b ticket_id "tkt_1a2b" booking_id "book_zyx" car_id "car_abc" seat_number "12A" ... is_checked_in 0 ... // To link tickets to bookings (optional): // SADD booking:book_zyx:tickets ticket:tkt_1a2b // Use Hashes for maintenance record details. Key format: maintenance_record:<record_id> // HSET maintenance_record:maint_rec_001 record_id "maint_rec_001" asset_id "train_789" asset_type "Train" ... status "Completed" // To link records to assets (optional): // SADD train:train_789:maintenance maintenance_record:maint_rec_001 // SADD platform:plat_123:maintenance maintenance_record:maint_rec_002 ##Table Structure CREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text ) ##Table Structure CREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text ) ##Table Structure CREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) ) ##Table Structure CREATE TABLE blockchain.transactions ( transaction_id text, block_id text, sender_address text, receiver_address text, amount numeric, timestamp timestamp, signature text ) CREATE TABLE blockchain.smart_contracts ( contract_id text, creator_address text, code text, timestamp timestamp ) ##Table Structure CREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text ) ##Table Structure CREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )
[ { "role": "user", "content": "Show the plan name and insurance provider for all insurance plans along with the total number of unique patients enrolled in each plan." }, { "role": "assistant", "content": "SELECT ip.plan_name, ip.insurance_provider, COUNT(DISTINCT pi.patient_id) AS enrolled_patient_count\nFROM healthcare.insurance_plans ip\nJOIN healthcare.patients_insurance pi ON ip.plan_id = pi.plan_id\nGROUP BY ip.plan_name, ip.insurance_provider;" }, { "role": "user", "content": "特定のプラットフォームID 'plat_123' に関連するメンテナンス記録を取得するのを手伝っていただけますか?また、記録のステータスも含めてください。" }, { "role": "assistant", "content": "SMEMBERS platform:plat_123:maintenance\nHGETALL maintenance_record:<record_id>" }, { "role": "user", "content": "ステータスが 'Completed' の記録だけを表示するようにフィルタリングしていただけますか?" }, { "role": "assistant", "content": "SMEMBERS platform:plat_123:maintenance\nHGET maintenance_record:<record_id> status\nHGETALL maintenance_record:<record_id> (only if status = 'Completed')" }, { "role": "user", "content": "関連する資産タイプも結果に含めていただけますか?" }, { "role": "assistant", "content": "SMEMBERS platform:plat_123:maintenance\nHGET maintenance_record:<record_id> status\nHGETALL maintenance_record:<record_id> (only if status = 'Completed')" }, { "role": "user", "content": "What is the average USD value per address for each narrative across all chains?" }, { "role": "assistant", "content": "SELECT\n narrative,\n AVG(usd_value / NULLIF(address_amount, 0)) AS avg_usd_per_address\nFROM smart_money_token_inflow\nGROUP BY narrative;" }, { "role": "user", "content": "How many documents are there for each document_type? Show document_type and count ordered by the count in descending order." }, { "role": "assistant", "content": "SELECT document_type,\n COUNT(*) AS count\nFROM legal_services.documents\nGROUP BY document_type\nORDER BY count DESC;" }, { "role": "user", "content": "List the reference number and status for all applications, including the registration date of the citizen who submitted it." }, { "role": "assistant", "content": "SELECT a.reference_number, a.status, c.registration_date FROM government_services.applications AS a JOIN citizens AS c ON a.citizen_id = c.citizen_id;" }, { "role": "user", "content": "Find all smart contracts deployed in 2022 that have never received any transactions." }, { "role": "assistant", "content": "SELECT sc.contract_id, sc.creator_address, sc.timestamp AS deployment_time\nFROM blockchain.smart_contracts sc\nLEFT JOIN blockchain.transactions t\n ON t.receiver_address = sc.contract_id\nWHERE sc.timestamp >= '2022-01-01' AND sc.timestamp < '2023-01-01'\n AND t.transaction_id IS NULL;" }, { "role": "user", "content": "Show me the names and phone numbers of all law firms founded in the same city." }, { "role": "assistant", "content": "SELECT lf1.firm_name AS firm1_name, lf1.phone AS firm1_phone, lf2.firm_name AS firm2_name, lf2.phone AS firm2_phone, lf1.address \nFROM legal_services.law_firms lf1\nJOIN legal_services.law_firms lf2 ON lf1.address = lf2.address AND lf1.firm_id < lf2.firm_id;" }, { "role": "user", "content": "Count the total number of likes each post has received." }, { "role": "assistant", "content": "SELECT post_id, COUNT(*) AS like_count\nFROM social_media.likes\nWHERE post_id IS NOT NULL\nGROUP BY post_id;" } ]
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.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp ) CREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp ) CREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text ) CREATE TABLE trading_platform.dapps ( dapp_id text, name text, description text, url text ) CREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp ) CREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) ) CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp ) CREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp ) ##Table Structure CREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, -- unique identifier for the user username character varying(50) NOT NULL UNIQUE, -- user's unique handle email character varying(128) NOT NULL UNIQUE, -- user's email address password_hash text NOT NULL, -- hashed password full_name character varying(100), -- user's full name profile_picture_url text, -- URL to the profile picture bio text, -- short user biography location character varying(100), -- user's location created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update is_verified boolean NOT NULL DEFAULT false, -- verification status PRIMARY KEY (user_id) ) CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, -- unique identifier for the comment post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id) user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id) parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id) content text NOT NULL, -- textual content of the comment created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit PRIMARY KEY (comment_id) ) CREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, -- unique identifier for the like user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id) post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable) comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something ) CREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id) following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows ) CREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used PRIMARY KEY (hashtag_id) ) CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated last_message_at timestamp, -- timestamp of the last message in the conversation is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message group_name character varying(100), -- name of the group chat (if applicable) PRIMARY KEY (conversation_id) ) CREATE TABLE social_media.conversation_participants ( participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id) user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id) joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation last_read_at timestamp, -- timestamp indicating up to when the user has read messages PRIMARY KEY (participant_id), CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times ) CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, -- unique identifier for the notification recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id) sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications) notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message') target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id) target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created read_at timestamp, -- timestamp notification was marked as read PRIMARY KEY (notification_id) ) CREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id) theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark') email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications private_profile boolean DEFAULT false, -- is the user profile private updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change PRIMARY KEY (setting_id) ) ##Table Structure CREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) ) 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.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_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 )
[ { "role": "user", "content": "List all DApps along with the number of metadata entries linked to each, even if the DApp has no linked metadata." }, { "role": "assistant", "content": "SELECT d.name, d.url, COUNT(m.metadata_id) AS metadata_count\nFROM trading_platform.dapps d\nLEFT JOIN trading_platform.metadata m ON d.dapp_id = m.asset_id\nGROUP BY d.dapp_id, d.name, d.url;" }, { "role": "user", "content": "List the usernames and user IDs of all users whose bio contains the word 'developer'." }, { "role": "assistant", "content": "SELECT user_id, username\nFROM social_media.users\nWHERE bio ILIKE '%developer%';" }, { "role": "user", "content": "How many likes have been received by public posts, grouped by media_type? Please show media_type and the count of likes for each." }, { "role": "assistant", "content": "SELECT p.media_type,\n COUNT(l.like_id) AS like_count\nFROM social_media.posts p\nJOIN social_media.likes l\n ON p.post_id = l.post_id\nWHERE p.visibility = 'public'\nGROUP BY p.media_type\nORDER BY like_count DESC;" } ]
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 Use Hashes. Key pattern: 'inv:<inventory_record_id>'. Example: HSET inv:INVREC500 component_id "component:WINGBOLT" quantity 5000 location_warehouse "WH3" batch_number "BCH778899" ... Consider Sorted Set by expiry date: ZADD component_expiry:<component_id> <expiry_timestamp> <inventory_record_id>. ##Table Structure CREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, -- unique identifier for the contract address character varying(128) NOT NULL, -- address of the deployed contract abi text NOT NULL, -- application binary interface of the contract bytecode text NOT NULL, -- bytecode of the contract deployer_address character varying(128) NOT NULL, -- address of the deployer deployed_at timestamp NOT NULL, -- time when the contract was deployed network_id character varying(64) NOT NULL, -- identifier of the network where the contract is deployed status character varying(32) NOT NULL, -- status of the contract (e.g., active, deprecated) PRIMARY KEY (contract_id) ) CREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction from_address character varying(128) NOT NULL, -- address of the sender to_address character varying(128), -- address of the receiver (can be null for contract deployment) value numeric(38,14) NOT NULL, -- value transferred gas_used integer NOT NULL, -- amount of gas used by the transaction gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction block_number integer NOT NULL, -- block number containing the transaction timestamp timestamp NOT NULL, -- time when the transaction was mined input_data text, -- input data of the transaction (can be null) status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed) nonce integer NOT NULL, -- nonce of the sender at the time of the transaction PRIMARY KEY (transaction_id) ) CREATE TABLE web3.wallets ( wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet address character varying(128) NOT NULL, -- address of the wallet private_key text NOT NULL, -- private key of the wallet created_at timestamp NOT NULL, -- time when the wallet was created PRIMARY KEY (wallet_id) ) ##Table Structure CREATE TABLE web3.tokens ( token_id character varying(64) NOT NULL, -- unique identifier for the token contract_address character varying(128) NOT NULL, -- address of the token contract token_name character varying(128) NOT NULL, -- name of the token token_symbol character varying(32) NOT NULL, -- symbol of the token decimals integer NOT NULL, -- number of decimals for the token total_supply numeric(38,14) NOT NULL, -- total supply of the token PRIMARY KEY (token_id) ) ##Table Structure CREATE TABLE government_services.service_locations ( location_id.text, agency_id.text, location_name.text, address.text, city.text, state.text, postal_code.text, latitude.numeric, longitude.numeric, operating_hours.text, contact_phone.text, is_accessible.boolean ) ##Table Structure CREATE TABLE government_services.services ( service_id text, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days integer, is_active boolean, online_application_url text ) ##Table Structure CREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text ) ##Table Structure CREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text ) ##Table Structure CREATE TABLE web3.tokens ( token_id character varying(64) NOT NULL, -- unique identifier for the token contract_address character varying(128) NOT NULL, -- address of the token contract token_name character varying(128) NOT NULL, -- name of the token token_symbol character varying(32) NOT NULL, -- symbol of the token decimals integer NOT NULL, -- number of decimals for the token total_supply numeric(38,14) NOT NULL, -- total supply of the token PRIMARY KEY (token_id) )
[ { "role": "user", "content": "Can you help me fetch the inventory records for components stored in a specific warehouse, along with their expiry dates?" }, { "role": "assistant", "content": "HGETALL inv:<inventory_record_id>\nZRANGE component_expiry:<component_id> 0 -1 WITHSCORES" }, { "role": "user", "content": "Can you filter this to show only records for a specific component ID?" }, { "role": "assistant", "content": "HGETALL inv:<inventory_record_id>\nZRANGE component_expiry:<component_id> 0 -1 WITHSCORES" }, { "role": "user", "content": "What if I want to exclude records with quantities below a certain threshold, like 100?" }, { "role": "assistant", "content": "HGETALL inv:<inventory_record_id>\nZRANGE component_expiry:<component_id> 0 -1 WITHSCORES\n# Note: Filtering by quantity would require additional scripting or client-side processing as Redis does not support direct filtering on hash field values." }, { "role": "user", "content": "Can you also sort the results by expiry date in descending order?" }, { "role": "assistant", "content": "HGETALL inv:<inventory_record_id>\nZREVRANGE component_expiry:<component_id> 0 -1 WITHSCORES" }, { "role": "user", "content": "Show each contract address and the count of successful transactions sent to that contract." }, { "role": "assistant", "content": "SELECT c.address, COUNT(t.transaction_id) AS success_tx_count FROM web3.contracts c JOIN web3.transactions t ON t.to_address = c.address AND t.status = 'success' GROUP BY c.address;" }, { "role": "user", "content": "List the token symbol, token name, and contract address for all tokens that have no recorded transfers in the token_transfers table." }, { "role": "assistant", "content": "SELECT T.token_symbol, T.token_name, T.contract_address FROM web3.tokens AS T LEFT JOIN token_transfers AS TT ON T.token_id = TT.token_id WHERE TT.transfer_id IS NULL;" }, { "role": "user", "content": "For each service location, find its nearest accessible location by geographic distance." }, { "role": "assistant", "content": "SELECT sl.location_id,\n sl.location_name,\n nearest.location_id AS nearest_location_id,\n nearest.location_name AS nearest_location_name\nFROM government_services.service_locations sl\nJOIN LATERAL (\n SELECT sl2.location_id,\n sl2.location_name\n FROM government_services.service_locations sl2\n WHERE sl2.is_accessible = TRUE\n AND sl2.location_id <> sl.location_id\n ORDER BY ((sl.latitude - sl2.latitude)^2 + (sl.longitude - sl2.longitude)^2) ASC\n LIMIT 1\n) AS nearest ON TRUE;" }, { "role": "user", "content": "For each agency, how many services are currently inactive? Return the agency_id and the count of inactive services." }, { "role": "assistant", "content": "SELECT\n agency_id,\n COUNT(*) AS inactive_service_count\nFROM government_services.services\nWHERE is_active = FALSE\nGROUP BY agency_id;" }, { "role": "user", "content": "Show the customer_id and pairs of payment_ids for any customers who have overlapping payment periods." }, { "role": "assistant", "content": "SELECT p1.customer_id,\n p1.payment_id AS payment1_id,\n p2.payment_id AS payment2_id\nFROM insurance.premium_payments p1\nJOIN insurance.premium_payments p2\n ON p1.customer_id = p2.customer_id\n AND p1.payment_id < p2.payment_id\n AND p1.payment_period_start <= p2.payment_period_end\n AND p1.payment_period_end >= p2.payment_period_start;" }, { "role": "user", "content": "For each location, count the total number of appointments scheduled. Show the location name and the count." }, { "role": "assistant", "content": "SELECT T2.location_name, COUNT(T1.appointment_id) FROM government_services.appointments AS T1 JOIN locations AS T2 ON T1.location_id = T2.location_id GROUP BY T2.location_name;" }, { "role": "user", "content": "Show all token symbols along with the names of any other tokens on the same contract address." }, { "role": "assistant", "content": "SELECT t1.token_symbol, t2.token_name AS other_token_name, t1.contract_address\nFROM web3.tokens t1\nJOIN web3.tokens t2\n ON t1.contract_address = t2.contract_address\n AND t1.token_id <> t2.token_id;" } ]
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.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) ) CREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) ) CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp ) CREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, -- unique identifier for the trade order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade buyer_id character varying(64) NOT NULL, -- identifier of the buyer seller_id character varying(64) NOT NULL, -- identifier of the seller asset_id character varying(64) NOT NULL, -- identifier of the asset being traded quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade price numeric(38,14) NOT NULL, -- price per unit of the asset traded_at timestamp NOT NULL, -- time when the trade was executed PRIMARY KEY (trade_id) ) CREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text ) CREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean ) CREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text ) CREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with key character varying(128) NOT NULL, -- key of the metadata value text NOT NULL, -- value of the metadata PRIMARY KEY (metadata_id) ) CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit user_id character varying(64) NOT NULL, -- identifier of the user being audited status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected) reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed PRIMARY KEY (kyc_audit_id) ) ##Table Structure CREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token avg_price numeric(38,6), -- the average cost price of user spent on this token type int, -- the direction of the trade on this token. 1 means buying, 2 means selling address_amount integer, -- the amount of the user bought this token narrative character varying(100), -- the category or narrative of the token chain character varying(100), -- the chain that the token resides ,PRIMARY KEY (token_address, chain) ) ##Table Structure CREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text ) ##Table Structure CREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, token_address character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, highest_price_24h double precision, lowest_price_24h double precision, market_cap double precision, market_cap_rank bigint, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank bigint ) ##Table Structure CREATE TABLE blockchain.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, PRIMARY KEY (user_id) ) ##Table Structure CREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, 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 ) ##Table Structure 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.conversation_participants ( participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id) user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id) joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation last_read_at timestamp, -- timestamp indicating up to when the user has read messages PRIMARY KEY (participant_id), CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times ) 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 ) ##Table Structure CREATE TABLE transportation.locations ( location_id.text, name.text, type.text, address_line1.text, city.text, state_province.text, postal_code.text, country.text, latitude.numeric, longitude.numeric, timezone.text )
[ { "role": "user", "content": "List the name and symbol for all assets that do not have a corresponding entry with the key 'website' in the metadata table." }, { "role": "assistant", "content": "SELECT T1.name , T1.symbol FROM trading_platform.assets AS T1 LEFT JOIN trading_platform.metadata AS T2 ON T1.asset_id = T2.asset_id AND T2.key = 'website' WHERE T2.metadata_id IS NULL" }, { "role": "user", "content": "For each chain, which token had the highest number of smart money addresses buying it this week? Show the token symbol and narrative too." }, { "role": "assistant", "content": "SELECT chain, token_symbol, narrative, MAX(address_amount) AS max_buyers FROM smart_money_token_inflow WHERE type = 1 AND DATE_TRUNC('week', CURRENT_DATE) = DATE_TRUNC('week', CURRENT_DATE) GROUP BY chain, token_symbol, narrative;" }, { "role": "user", "content": "I got an error, I think the filter for the week may be wrong. Please revise the query so that it only counts buys from the current week." }, { "role": "assistant", "content": "SELECT chain, token_symbol, narrative, address_amount AS buyers FROM smart_money_token_inflow WHERE type = 1 AND EXTRACT(week FROM CURRENT_DATE) = EXTRACT(week FROM CURRENT_DATE) AND EXTRACT(year FROM CURRENT_DATE) = EXTRACT(year FROM CURRENT_DATE) ORDER BY chain, buyers DESC;" }, { "role": "user", "content": "List all claim documents where the description contains the word 'invoice'." }, { "role": "assistant", "content": "SELECT document_id, claim_id, file_name, description FROM insurance.claim_documents WHERE description ILIKE '%invoice%';" }, { "role": "user", "content": "List all tokens with a price below $1 and a 24-hour trading volume over $5 million." }, { "role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume FROM token_basic_info WHERE price < 1 AND total_volume::numeric > 5000000;" }, { "role": "user", "content": "Can you provide a count of users for each unique email domain?" }, { "role": "assistant", "content": "SELECT SUBSTRING(email FROM POSITION('@' IN email) + 1), COUNT(*) FROM blockchain.users GROUP BY SUBSTRING(email FROM POSITION('@' IN email) + 1);" }, { "role": "user", "content": "Show the number of active agents in each license state." }, { "role": "assistant", "content": "SELECT license_state,\n COUNT(*) AS active_agent_count\nFROM insurance.agents\nWHERE status = 'active'\nGROUP BY license_state;" }, { "role": "user", "content": "How many posts have been updated after they were created?" }, { "role": "assistant", "content": "SELECT COUNT(*) AS updated_post_count\nFROM social_media.posts\nWHERE updated_at IS NOT NULL AND updated_at > created_at;" }, { "role": "user", "content": "Provide a count of locations for each country listed in the table." }, { "role": "assistant", "content": "SELECT country, COUNT(*) FROM transportation.locations GROUP BY country" } ]
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.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp ) ##Table Structure CREATE TABLE web3.events ( event_id character varying(64) NOT NULL, -- unique identifier for the event contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event event_name character varying(128) NOT NULL, -- name of the event data text NOT NULL, -- data payload of the event emitted_at timestamp NOT NULL, -- time when the event was emitted transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event log_index integer NOT NULL, -- index of the event log in the transaction PRIMARY KEY (event_id) ) CREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) ) CREATE TABLE web3.token_transfers ( transfer_id text, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index integer ) ##Table Structure CREATE TABLE web3.events ( event_id character varying(64) NOT NULL, -- unique identifier for the event contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event event_name character varying(128) NOT NULL, -- name of the event data text NOT NULL, -- data payload of the event emitted_at timestamp NOT NULL, -- time when the event was emitted transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event log_index integer NOT NULL, -- index of the event log in the transaction PRIMARY KEY (event_id) ) CREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) ) CREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric ) CREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp ) CREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp ) ##Table Structure CREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text ) ##Table Structure CREATE TABLE healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) ) CREATE TABLE healthcare.appointments ( appointment_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, appointment_time timestamp with time zone NOT NULL, duration_minutes integer NOT NULL, reason text, status character varying(32) NOT NULL, location_id character varying(64), notes text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) ) CREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) ) ##Table Structure CREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) ) ##Table Structure CREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )
[ { "role": "user", "content": "Provide a count of notifications, separated by whether they have been read or not." }, { "role": "assistant", "content": "SELECT CASE WHEN T1.read_at IS NULL THEN 'Unread' ELSE 'Read' END, count(T1.notification_id) FROM trading_platform.notifications AS T1 GROUP BY CASE WHEN T1.read_at IS NULL THEN 'Unread' ELSE 'Read' END" }, { "role": "user", "content": "Show the transaction ID, the transaction value from the transactions table, and the sum of the value from token_transfers for all transactions that have at least one associated token transfer. Name the sum column total_token_transfer_value." }, { "role": "assistant", "content": "SELECT t.transaction_id, t.value AS transaction_native_value, SUM(tt.value) AS total_token_transfer_value FROM web3.transactions t JOIN web3.token_transfers tt ON t.transaction_id = tt.transaction_id GROUP BY t.transaction_id, t.value;" }, { "role": "user", "content": "For each event recorded, list its ID, name, and the status and value of the transaction in which it occurred." }, { "role": "assistant", "content": "SELECT E.event_id, E.event_name, E.transaction_id, T.status, T.value FROM web3.events AS E JOIN web3.transactions AS T ON E.transaction_id = T.transaction_id;" }, { "role": "user", "content": "Show all medications that share a manufacturer with at least one other medication. Return the medication_id, medication_name, and manufacturer for each." }, { "role": "assistant", "content": "SELECT m.medication_id,\n m.medication_name,\n m.manufacturer\nFROM healthcare.medications m\nJOIN (\n SELECT manufacturer\n FROM healthcare.medications\n GROUP BY manufacturer\n HAVING COUNT(*) > 1\n) multi ON m.manufacturer = multi.manufacturer;" }, { "role": "user", "content": "List all appointments that are currently scheduled and show their appointment time." }, { "role": "assistant", "content": "SELECT appointment_id, patient_id, doctor_id, appointment_time FROM healthcare.appointments WHERE status = 'Scheduled';" }, { "role": "user", "content": "List tokens with trend rank 5 or better and a price below $1. Show symbol, price, and trend rank." }, { "role": "assistant", "content": "SELECT token_symbol, price, trend_rank FROM token_dexpool_info WHERE trend_rank IS NOT NULL AND trend_rank <= 5 AND price < 1;" }, { "role": "user", "content": "How many documents exist for each document_type? Return document_type and the count." }, { "role": "assistant", "content": "SELECT document_type,\n COUNT(*) AS document_count\nFROM insurance.claim_documents\nGROUP BY document_type;" } ]
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.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL DEFAULT 'USA', phone_number character varying(30), email character varying(128) UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, status character varying(20) NOT NULL DEFAULT 'Active', PRIMARY KEY (customer_id) ) CREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) ) CREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) ) CREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) ) CREATE TABLE insurance.premium_payments ( payment_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, amount_paid numeric(12, 2) NOT NULL, payment_method character varying(50), transaction_reference character varying(128) UNIQUE, due_date date, payment_period_start date, payment_period_end date, status character varying(30) NOT NULL DEFAULT 'Completed', PRIMARY KEY (payment_id) ) CREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) ) CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) ) ##Table Structure CREATE TABLE healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) ) CREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp ) CREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry patient_id character varying(64) NOT NULL, -- FK to patients table doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor) diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10) code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used description text, -- textual description of the diagnosis diagnosis_date date NOT NULL, -- date the diagnosis was made status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out is_chronic boolean DEFAULT false, -- flag for chronic conditions PRIMARY KEY (diagnosis_id) ) CREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp ) CREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text ) CREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean ) ##Table Structure CREATE TABLE web3.token_transfers ( transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer token_id character varying(64) NOT NULL, -- identifier of the token being transferred from_address character varying(128) NOT NULL, -- address of the sender to_address character varying(128) NOT NULL, -- address of the receiver value numeric(38,14) NOT NULL, -- amount of tokens transferred transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer log_index integer NOT NULL, -- index of the transfer log in the transaction PRIMARY KEY (transfer_id) ) ##Table Structure CREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text ) ##Table Structure CREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )
[ { "role": "user", "content": "What is the average commission rate for all active agents?" }, { "role": "assistant", "content": "SELECT AVG(commission_rate) FROM agents WHERE status = 'Active';" }, { "role": "user", "content": "List the full names and dates of birth for all patients who do not have a phone number on record." }, { "role": "assistant", "content": "SELECT first_name, last_name, date_of_birth FROM healthcare.patients WHERE phone_number IS NULL OR TRIM(phone_number) = '';" }, { "role": "user", "content": "Find cases where an address received tokens in one transfer and then sent tokens in another. List the receive transfer_id, the send transfer_id, the address, and both transfer values." }, { "role": "assistant", "content": "SELECT recv.transfer_id AS receive_transfer_id,\n send.transfer_id AS send_transfer_id,\n recv.to_address AS address,\n recv.value AS received_value,\n send.value AS sent_value\nFROM web3.token_transfers recv\nJOIN web3.token_transfers send\n ON recv.to_address = send.from_address;" }, { "role": "user", "content": "List the first_name, last_name, and email of all clients whose email domain is 'gmail.com'." }, { "role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.clients WHERE SUBSTRING(email FROM POSITION('@' IN email) + 1) = 'gmail.com';" }, { "role": "user", "content": "List all medications with a description that includes the word 'antibiotic'." }, { "role": "assistant", "content": "SELECT * FROM healthcare.medications WHERE description ILIKE '%antibiotic%';" } ]
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.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date ) CREATE TABLE transportation.maintenance_logs ( log_id text, vehicle_id text, service_date date, odometer_reading integer, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date ) CREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text ) CREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp ) 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 ) ##Table Structure CREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry patient_id character varying(64) NOT NULL, -- FK to patients table appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt) doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record) record_date timestamp with time zone NOT NULL, -- date the record/observation was made chief_complaint text, -- patient's primary reason for visit present_illness_history text, -- detailed history of the current issue past_medical_history text, -- relevant past conditions/surgeries physical_examination_notes text, -- findings from the physical exam assessment text, -- doctor's assessment/diagnosis summary treatment_plan text, -- planned course of action vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) ) CREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text ) ##Table Structure CREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer ) ##Table Structure CREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) ) CREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text ) CREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text ) CREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) ) CREATE TABLE government_services.employees ( employee_id.text, agency_id.text, first_name.text, last_name.text, job_title.text, department.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, access_level.text, manager_employee_id.text ) CREATE TABLE government_services.service_locations ( location_id.text, agency_id.text, location_name.text, address.text, city.text, state.text, postal_code.text, latitude.numeric, longitude.numeric, operating_hours.text, contact_phone.text, is_accessible.boolean ) CREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text ) CREATE TABLE government_services.notifications ( notification_id.text, citizen_id.text, application_id.text, message_subject.text, message_body.text, channel.text, sent_at.timestamp, status.text, related_entity_type.text, related_entity_id.text ) ##Table Structure CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp ) CREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text ) CREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp ) CREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text ) CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp ) CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp ) CREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp ) ##Table Structure CREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )
[ { "role": "user", "content": "For each trip, can you show the trip_id, number of passengers, and the make and model of the assigned vehicle?" }, { "role": "assistant", "content": "SELECT b.trip_id, COUNT(b.passenger_id) AS passenger_count, v.make, v.model\nFROM transportation.bookings b\nJOIN transportation.vehicles v ON b.trip_id IN (\n SELECT DISTINCT trip_id FROM transportation.fuel_logs WHERE vehicle_id = v.vehicle_id\n)\nGROUP BY b.trip_id, v.make, v.model;" }, { "role": "user", "content": "I want to list all insurance plans along with the number of medical records that have a record_date in 2024. Display plan_id, plan_name, and the total medical records." }, { "role": "assistant", "content": "SELECT ip.plan_id, ip.plan_name, COUNT(mr.record_id) AS total_medical_records\nFROM healthcare.insurance_plans ip\nLEFT JOIN healthcare.medical_records mr ON 1=0 -- there is no direct relationship in schema, so no records will be counted\nWHERE mr.record_date >= '2024-01-01' AND mr.record_date < '2025-01-01'\nGROUP BY ip.plan_id, ip.plan_name;" }, { "role": "user", "content": "Since there's no direct relationship, can you adjust it to just show all insurance plans of type 'EPO' with their plan_id and plan_name?" }, { "role": "assistant", "content": "SELECT plan_id, plan_name\nFROM healthcare.insurance_plans\nWHERE plan_type = 'EPO';" }, { "role": "user", "content": "For each transaction, find the next transaction initiated by the same sender. List the original transaction_id, the next transaction_id, the sender address, and the time difference in hours between them." }, { "role": "assistant", "content": "SELECT t1.transaction_id AS original_tx,\n t2.transaction_id AS next_tx,\n t1.from_address,\n EXTRACT(EPOCH FROM (t2.timestamp - t1.timestamp)) / 3600 AS hours_diff\nFROM transactions t1\nJOIN transactions t2\n ON t1.from_address = t2.from_address\n AND t2.timestamp = (\n SELECT MIN(timestamp)\n FROM transactions t3\n WHERE t3.from_address = t1.from_address\n AND t3.timestamp > t1.timestamp\n );" }, { "role": "user", "content": "Find all service locations that currently have no appointments scheduled. Display the location name and contact phone number." }, { "role": "assistant", "content": "SELECT sl.location_name,\n sl.contact_phone\nFROM government_services.service_locations sl\nLEFT JOIN government_services.appointments ap ON sl.location_id = ap.location_id\nWHERE ap.appointment_id IS NULL;" }, { "role": "user", "content": "How many unread notifications does each user have?" }, { "role": "assistant", "content": "SELECT user_id,\n COUNT(*) AS unread_notifications\nFROM trading_platform.notifications\nWHERE read_at IS NULL\nGROUP BY user_id;" }, { "role": "user", "content": "Show the distribution of cases by their current status, listing each status and the total count of cases in that status." }, { "role": "assistant", "content": "SELECT status, COUNT(*) AS case_count FROM legal_services.cases GROUP BY status ORDER BY case_count DESC;" } ]
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 government_services.agencies ( agency_id character varying(64) NOT NULL, -- unique identifier for the agency agency_name character varying(255) NOT NULL, -- full name of the government agency jurisdiction_level character varying(50) NOT NULL, -- e.g., Federal, State, County, City primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), -- FK to self for hierarchical structure PRIMARY KEY (agency_id) ) CREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, -- unique identifier for the document instance application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly) citizen_id character varying(64) NOT NULL, -- FK to citizens table document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path) upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected verified_by_employee_id character varying(64), -- FK to employees table verification_timestamp timestamp, PRIMARY KEY (document_id) ) ##Table Structure CREATE TABLE project_fundraising_record ( id.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric ) ##Table Structure CREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer ) CREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text ) CREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text ) CREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer ) CREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text ) CREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer ) CREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text ) CREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text ) CREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text ) CREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer ) CREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer ) CREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp ) CREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp ) CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer ) CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal ) CREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text ) CREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text ) CREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint ) CREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text ) CREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text ) CREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text ) CREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text ) CREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal ) ##Table Structure CREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO output_index integer NOT NULL, -- index of the output in the transaction address character varying(128) NOT NULL, -- address that can spend the UTXO amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO spent boolean NOT NULL, -- whether the UTXO has been spent PRIMARY KEY (utxo_id) )
[ { "role": "user", "content": "Show me a list of all agencies and the number of distinct citizens who have submitted documents to each agency." }, { "role": "assistant", "content": "SELECT a.agency_name, COUNT(DISTINCT d.citizen_id) AS citizen_count\nFROM government_services.documents d\nJOIN government_services.applications app ON d.application_id = app.application_id\nJOIN government_services.services s ON app.service_id = s.service_id\nJOIN government_services.agencies a ON s.agency_id = a.agency_id\nGROUP BY a.agency_name;" }, { "role": "user", "content": "What is the total investment_value per fundraising round for the year 2023? Order by total investment descending." }, { "role": "assistant", "content": "SELECT\n substr(investment_date,1,7) AS month,\n rounds_name,\n SUM(investment_value) AS total_investment\nFROM project_fundraising_record\nWHERE investment_date LIKE '2023-%'\nGROUP BY substr(investment_date,1,7), rounds_name\nORDER BY total_investment DESC;" }, { "role": "user", "content": "Show the symbol, name, and total supply for all SUI coins with status 'active'." }, { "role": "assistant", "content": "SELECT scm.symbol, scm.name, scm.coin_type, scm.total_supply\nFROM sui_coins_metadata scm\nWHERE scm.status = 'active';" }, { "role": "user", "content": "I received an error that column 'total_supply' doesn't exist in sui_coins_metadata." }, { "role": "assistant", "content": "SELECT scm.symbol, scm.name, scm.coin_type\nFROM sui_coins_metadata scm\nWHERE scm.status = 'active';" }, { "role": "user", "content": "Now, join with sui_coins to add up the total balance across all owners for each coin_type." }, { "role": "assistant", "content": "SELECT scm.symbol, scm.name, scm.coin_type, SUM(CAST(sc.balance AS NUMERIC)) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'active'\nGROUP BY scm.symbol, scm.name, scm.coin_type;" }, { "role": "user", "content": "For each transaction ID, provide a count of unspent UTXOs." }, { "role": "assistant", "content": "SELECT transaction_id, COUNT(*) FROM utxos WHERE spent = FALSE GROUP BY transaction_id;" } ]
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 government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) ) ##Table Structure CREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, -- unique identifier for the employee first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst department character varying(100), -- e.g., Retail Banking, Wealth Management, IT branch_id character varying(64), -- Identifier for the branch they work at (if applicable) email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, -- Date of termination, null if currently employed manager_id character varying(64), -- Self-referencing key for manager relationship status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) ) ##Table Structure CREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, specialty character varying(100) NOT NULL, license_number character varying(50) UNIQUE NOT NULL, phone_number character varying(20), email character varying(128) UNIQUE, hospital_affiliation_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (doctor_id) ) CREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) ) ##Table Structure CREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.) property_name character varying(255) NOT NULL, -- name of the property address_line1 character varying(255) NOT NULL, -- primary address line address_line2 character varying(255), -- secondary address line city character varying(100) NOT NULL, -- city state_province character varying(100), -- state or province postal_code character varying(20) NOT NULL, -- zip or postal code country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN) phone_number character varying(30), -- main contact phone email_address character varying(255), -- main contact email property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel star_rating numeric(2,1), -- star rating (e.g., 4.5) timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York) manager_staff_id character varying(64), -- FK to staff table for the general manager created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time PRIMARY KEY (property_id) ) CREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, -- unique identifier for the room property_id character varying(64) NOT NULL, -- FK to properties table room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B') room_type_id character varying(64) NOT NULL, -- FK to room_types table floor integer, -- floor number the room is on status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi) current_condition text, -- notes on room condition last_cleaned_at timestamp with time zone, -- timestamp of last cleaning PRIMARY KEY (room_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) ) CREATE TABLE hospitality_technology.staff ( staff_id character varying(64) NOT NULL, -- unique identifier for the staff member property_id character varying(64) NOT NULL, -- FK to properties table (primary property) first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge work_email character varying(255) UNIQUE, -- staff member's work email work_phone character varying(30), hire_date date NOT NULL, termination_date date, -- date employment ended (if applicable) is_active boolean NOT NULL DEFAULT true, -- currently employed flag access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin) manager_id character varying(64), -- FK to staff table (self-referencing for supervisor) created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (staff_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id) ) CREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, -- unique identifier for the review property_id character varying(64) NOT NULL, -- FK to properties table reservation_id character varying(64) UNIQUE, -- FK to reservations (link review to a specific stay, optional but good) guest_id character varying(64) NOT NULL, -- FK to guests table rating_overall integer, -- overall score (e.g., 1-5 or 1-10) rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, -- guest's written feedback review_source character varying(100), -- e.g., DirectSurvey, TripAdvisor, Google, Booking.com review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the review was submitted is_public boolean DEFAULT true, -- whether the review is publicly visible staff_response text, -- official response from the property response_staff_id character varying(64), -- FK to staff (who responded) response_date timestamp with time zone, -- when the response was posted PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )
[ { "role": "user", "content": "How many documents of each type currently have a verification_status of 'Pending'?" }, { "role": "assistant", "content": "SELECT\n document_type,\n COUNT(*) AS pending_count\nFROM government_services.documents\nWHERE verification_status = 'Pending'\nGROUP BY document_type;" }, { "role": "user", "content": "Report the number of employees for each department, broken down by their employment status." }, { "role": "assistant", "content": "SELECT department, status, COUNT(*) AS employee_count FROM financial_services.employees GROUP BY department, status" }, { "role": "user", "content": "How many prescriptions are there for each refills_allowed value?" }, { "role": "assistant", "content": "SELECT refills_allowed,\n COUNT(*) AS prescription_count\nFROM healthcare.prescriptions\nGROUP BY refills_allowed;" }, { "role": "user", "content": "Show the first name, last name, and position of all staff members who are not currently active." }, { "role": "assistant", "content": "SELECT first_name , last_name , position FROM hospitality_technology.staff WHERE is_active = false" } ]
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 healthcare.medical_records ( record_id.text, patient_id.text, appointment_id.text, doctor_id.text, record_date.timestamp, chief_complaint.text, present_illness_history.text, past_medical_history.text, physical_examination_notes.text, assessment.text, treatment_plan.text, vitals.json, created_at.timestamp ) CREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean ) ##Table Structure CREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) ) CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, -- unique identifier for the comment post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id) user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id) parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id) content text NOT NULL, -- textual content of the comment created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit PRIMARY KEY (comment_id) ) CREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp ) CREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp ) CREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) ) CREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id) hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id) PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post ) CREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp ) CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated last_message_at timestamp, -- timestamp of the last message in the conversation is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message group_name character varying(100), -- name of the group chat (if applicable) PRIMARY KEY (conversation_id) ) CREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_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 ) ##Table Structure CREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) ) ##Table Structure CREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text ) CREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text ) CREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text ) CREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp ) 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 ) CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp ) ##Table Structure CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_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.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) ) CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp ) ##Table Structure CREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )
[ { "role": "user", "content": "For each patient, find the date of their most recent medical record and the effective date of their current primary insurance plan. Return patient_id, last_record_date, and effective_date." }, { "role": "assistant", "content": "SELECT m.patient_id,\n m.last_date AS last_record_date,\n pi.effective_date\nFROM (\n SELECT patient_id,\n MAX(record_date) AS last_date\n FROM healthcare.medical_records\n GROUP BY patient_id\n) m\nJOIN healthcare.patient_insurance pi\n ON m.patient_id = pi.patient_id\nWHERE pi.is_primary = TRUE;" }, { "role": "user", "content": "List all hashtags that have been used on posts created in the last 90 days. Show the tag_name and the date it was first used on a post within this period." }, { "role": "assistant", "content": "SELECT h.tag_name, MIN(p.created_at) AS first_use_date_in_period FROM social_media.posts AS p JOIN social_media.post_hashtags AS ph ON p.post_id = ph.post_id JOIN social_media.hashtags AS h ON ph.hashtag_id = h.hashtag_id WHERE p.created_at >= NOW() - INTERVAL '90 days' GROUP BY h.hashtag_id, h.tag_name;" }, { "role": "user", "content": "Show me the number of guests registered in each city. Order the results by city name." }, { "role": "assistant", "content": "SELECT city, COUNT(guest_id) AS guest_count FROM guests GROUP BY city ORDER BY city;" }, { "role": "user", "content": "What is the average commission rate for active agents?" }, { "role": "assistant", "content": "SELECT AVG(commission_rate) FROM insurance.agents WHERE status = 'Active';" }, { "role": "user", "content": "What is the total and average amount of unspent UTXOs per address?" }, { "role": "assistant", "content": "SELECT\n address,\n COUNT(*) AS utxo_count,\n SUM(amount) AS total_unspent_amount,\n AVG(amount) AS average_unspent_amount\nFROM trading_platform.utxos\nWHERE spent = FALSE\nGROUP BY address;" }, { "role": "user", "content": "How many lawyers are there in each specialization, and what is the count per specialization?" }, { "role": "assistant", "content": "SELECT specialization,\n COUNT(*) AS lawyer_count\nFROM legal_services.lawyers\nGROUP BY specialization;" } ]
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.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text ) CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, -- unique identifier for the notification recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id) sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications) notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message') target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id) target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created read_at timestamp, -- timestamp notification was marked as read PRIMARY KEY (notification_id) ) ##Table Structure CREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text ) ##Table Structure CREATE TABLE gaming_technology.players ( player_id.uuid, username.text, email.text, password_hash.text, registration_date.timestamptz, last_login.timestamptz, country_code.text, status.text, profile_data.jsonb ) CREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz ) CREATE TABLE gaming_technology.game_sessions ( session_id.uuid, player_id.uuid, game_id.uuid, server_id.uuid, start_time.timestamptz, end_time.timestamptz, duration_seconds.integer, score.integer, session_data.jsonb ) CREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean ) ##Table Structure CREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text ) CREATE TABLE government_services.services ( service_id.text, agency_id.text, service_name.text, description.text, category.text, eligibility_criteria.text, standard_fee.numeric, average_processing_time_days.integer, is_active.boolean, online_application_url.text ) CREATE TABLE government_services.applications ( application_id.text, citizen_id.text, service_id.text, submitted_at.timestamp, status.text, last_updated_at.timestamp, assigned_employee_id.text, decision_date.date, notes.text, reference_number.text ) CREATE TABLE government_services.documents ( document_id.text, application_id.text, citizen_id.text, document_type.text, file_reference.text, upload_timestamp.timestamp, expiry_date.date, verification_status.text, verified_by_employee_id.text, verification_timestamp.timestamp ) CREATE TABLE government_services.payments ( payment_id.text, application_id.text, citizen_id.text, service_id.text, amount.numeric, currency.text, payment_method.text, payment_provider_reference.text, payment_timestamp.timestamp, status.text, notes.text ) CREATE TABLE government_services.employees ( employee_id.text, agency_id.text, first_name.text, last_name.text, job_title.text, department.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, access_level.text, manager_employee_id.text ) CREATE TABLE government_services.service_locations ( location_id.text, agency_id.text, location_name.text, address.text, city.text, state.text, postal_code.text, latitude.numeric, longitude.numeric, operating_hours.text, contact_phone.text, is_accessible.boolean ) CREATE TABLE government_services.appointments ( appointment_id.text, citizen_id.text, employee_id.text, location_id.text, service_id.text, scheduled_start_time.timestamp, scheduled_end_time.timestamp, purpose.text, status.text, booking_method.text, created_at.timestamp, notes.text ) CREATE TABLE government_services.notifications ( notification_id.text, citizen_id.text, application_id.text, message_subject.text, message_body.text, channel.text, sent_at.timestamp, status.text, related_entity_type.text, related_entity_id.text ) ##Table Structure CREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text ) ##Table Structure CREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) ) ##Table Structure CREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )
[ { "role": "user", "content": "How many unread notifications are there with the type 'mention'?" }, { "role": "assistant", "content": "SELECT COUNT(*) FROM social_media.notifications WHERE read_at IS NULL AND notification_type = 'mention';" }, { "role": "user", "content": "List each driver along with the driver_id of the driver who was hired immediately after them." }, { "role": "assistant", "content": "SELECT d1.driver_id AS current_driver_id, d2.driver_id AS next_driver_id FROM transportation.drivers d1 LEFT JOIN transportation.drivers d2 ON d2.hire_date = (SELECT MIN(hire_date) FROM transportation.drivers WHERE hire_date > d1.hire_date);" }, { "role": "user", "content": "For each achievement, show its name, the game_id it belongs to, and the number of distinct players who have played a session for that game." }, { "role": "assistant", "content": "SELECT a.name, a.game_id, COUNT(DISTINCT gs.player_id) AS players_with_sessions\nFROM gaming_technology.achievements a\nLEFT JOIN gaming_technology.game_sessions gs ON a.game_id = gs.game_id\nGROUP BY a.achievement_id, a.name, a.game_id;" }, { "role": "user", "content": "Now, filter to only include achievements for games that have at least 50 players who have played a session." }, { "role": "assistant", "content": "SELECT a.name, a.game_id, COUNT(DISTINCT gs.player_id) AS players_with_sessions\nFROM gaming_technology.achievements a\nLEFT JOIN gaming_technology.game_sessions gs ON a.game_id = gs.game_id\nGROUP BY a.achievement_id, a.name, a.game_id\nHAVING COUNT(DISTINCT gs.player_id) >= 50;" }, { "role": "user", "content": "Please also include the number of times each achievement has been unlocked by unique players, labeled as unique_unlocks." }, { "role": "assistant", "content": "SELECT a.name, a.game_id, COUNT(DISTINCT gs.player_id) AS players_with_sessions,\n (SELECT COUNT(DISTINCT gs2.player_id)\n FROM gaming_technology.game_sessions gs2\n WHERE gs2.game_id = a.game_id) AS unique_unlocks\nFROM gaming_technology.achievements a\nLEFT JOIN gaming_technology.game_sessions gs ON a.game_id = gs.game_id\nGROUP BY a.achievement_id, a.name, a.game_id\nHAVING COUNT(DISTINCT gs.player_id) >= 50;" }, { "role": "user", "content": "I think unique_unlocks should be the count of distinct players who have unlocked each specific achievement, not just played a session. Can you correct that?" }, { "role": "assistant", "content": "-- With the provided tables, there is no direct record of players unlocking a specific achievement, unless unlocking is inferred elsewhere. If you have an achievement unlocks table, you could join it here. Otherwise, only possible to count sessions per game." }, { "role": "user", "content": "Find the names and addresses of service locations where no appointments have been scheduled." }, { "role": "assistant", "content": "SELECT sl.location_name, sl.address FROM government_services.service_locations sl LEFT JOIN government_services.appointments a ON sl.location_id = a.location_id WHERE a.appointment_id IS NULL;" }, { "role": "user", "content": "Count the number of completed premium payments grouped by payment_method." }, { "role": "assistant", "content": "SELECT payment_method,\n COUNT(*) AS payment_count\nFROM insurance.premium_payments\nWHERE status = 'Completed'\nGROUP BY payment_method;" }, { "role": "user", "content": "Count the number of services in each category. Return the category and the count." }, { "role": "assistant", "content": "SELECT category, COUNT(*) AS service_count FROM government_services.services GROUP BY category;" }, { "role": "user", "content": "Show the usernames and registration dates for all users whose email ends with '@gmail.com'." }, { "role": "assistant", "content": "SELECT username, created_at FROM web3.users WHERE email LIKE '%@gmail.com';" }, { "role": "user", "content": "Actually, can you also include how many such users there are in total in the result?" }, { "role": "assistant", "content": "SELECT username, created_at, COUNT(*) OVER() AS total_gmail_users FROM web3.users WHERE email LIKE '%@gmail.com';" } ]
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 // Use Hashes for platform details. Key format: platform:<platform_id> // HSET platform:plat_123 platform_id "plat_123" station_id "station_xyz" platform_number "1A" track_number "T1" status "Operational" length_meters 250.50 accessible 1 // To link platforms to stations (optional): // SADD station:station_xyz:platforms platform:plat_123 platform:plat_456 // Use Hashes for train details. Key format: train:<train_id> // HSET train:train_789 train_id "train_789" train_number "Acela 2151" model "Siemens Velaro" ... status "Active" ... // To find train by train_number (optional index): // SET train_number:"Acela 2151" train:train_789 // Use Hashes for car details. Key format: car:<car_id> // HSET car:car_abc car_id "car_abc" train_id "train_789" car_number "C3" car_type "Passenger" class "Business" capacity 60 features "WiFi,Power Outlet" // To link cars to trains (optional): // SADD train:train_789:cars car:car_abc car:car_def // Use Hashes for details. Key format: route_station:<route_station_id> // HSET route_station:rs_ne_1 route_station_id "rs_ne_1" route_id "route_ne_corr" station_id "station_bos" sequence_order 1 ... // To find stops for a route, use a Sorted Set (score by sequence_order): // ZADD route:route_ne_corr:stops 1 route_station:rs_ne_1 // ZADD route:route_ne_corr:stops 2 route_station:rs_ne_2 // Use Hashes for schedule details. Key format: schedule:<schedule_id> // HSET schedule:sched_1122 schedule_id "sched_1122" train_id "train_789" route_id "route_ne_corr" departure_datetime "2024-05-10T08:00:00-04:00" ... status "Scheduled" // Use Hashes for details. Key format: schedule_stop:<stop_id> // HSET schedule_stop:stop_sched1122_1 stop_id "stop_sched1122_1" schedule_id "sched_1122" station_id "station_bos" ... // To find stops for a schedule, use a Sorted Set (score by sequence_order): // ZADD schedule:sched_1122:stops 1 schedule_stop:stop_sched1122_1 // ZADD schedule:sched_1122:stops 2 schedule_stop:stop_sched1122_2 // Use Hashes for passenger details. Key format: passenger:<passenger_id> // HSET passenger:pass_pqr passenger_id "pass_pqr" first_name "Alice" last_name "Smith" email "alice.smith@example.com" ... // To find passenger by email (optional index): // SET passenger_email:"alice.smith@example.com" passenger:pass_pqr // Use Hashes for booking details. Key format: booking:<booking_id> // HSET booking:book_zyx booking_id "book_zyx" passenger_id "pass_pqr" schedule_id "sched_1122" ... status "Confirmed" ... // To link bookings to passengers/schedules (optional): // SADD passenger:pass_pqr:bookings booking:book_zyx // SADD schedule:sched_1122:bookings booking:book_zyx // Use Hashes for ticket details. Key format: ticket:<ticket_id> // HSET ticket:tkt_1a2b ticket_id "tkt_1a2b" booking_id "book_zyx" car_id "car_abc" seat_number "12A" ... is_checked_in 0 ... // To link tickets to bookings (optional): // SADD booking:book_zyx:tickets ticket:tkt_1a2b // Use Hashes for staff details. Key format: staff:<staff_id> // HSET staff:staff_mno staff_id "staff_mno" first_name "Bob" ... employee_number "E12345" ... is_active 1 // To find staff by employee number (optional index): // SET staff_employee_number:"E12345" staff:staff_mno // Use Hashes for maintenance record details. Key format: maintenance_record:<record_id> // HSET maintenance_record:maint_rec_001 record_id "maint_rec_001" asset_id "train_789" asset_type "Train" ... status "Completed" // To link records to assets (optional): // SADD train:train_789:maintenance maintenance_record:maint_rec_001 // SADD platform:plat_123:maintenance maintenance_record:maint_rec_002 ##Table Structure CREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text ) CREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, 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 PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp ) ##Table Structure CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) ) ##Table Structure CREATE TABLE transportation.drivers ( driver_id text, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text ) ##Table Structure CREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )
[ { "role": "user", "content": "I need to find all bookings for a specific schedule with schedule_id 'sched_1122' and include the passenger and ticket details." }, { "role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGETALL ticket:tkt_*" }, { "role": "user", "content": "Can you filter the tickets to show only those that are not checked in?" }, { "role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGET ticket:tkt_* is_checked_in\nIF is_checked_in == 0 THEN\nHGETALL ticket:tkt_*\nENDIF" }, { "role": "user", "content": "Can you also include the car details for each ticket?" }, { "role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGET ticket:tkt_* is_checked_in\nIF is_checked_in == 0 THEN\nHGETALL ticket:tkt_*\nHGET ticket:tkt_* car_id\nHGETALL car:car_*\nENDIF" }, { "role": "user", "content": "List all users with private profiles who have disabled push notifications, including their user_id and email_notifications_enabled status." }, { "role": "assistant", "content": "SELECT user_id,\n email_notifications_enabled\nFROM social_media.user_settings\nWHERE private_profile = true\n AND push_notifications_enabled = false;" }, { "role": "user", "content": "How many beneficiaries are there for each relationship type?" }, { "role": "assistant", "content": "SELECT relationship,\n COUNT(*) AS beneficiary_count\nFROM insurance.policy_beneficiaries\nGROUP BY relationship;" }, { "role": "user", "content": "For each driver, show their driver_id, email, and the number of days until their license expires." }, { "role": "assistant", "content": "SELECT driver_id, email, (license_expiry_date - CURRENT_DATE) AS days_until_expiry\nFROM transportation.drivers;" }, { "role": "user", "content": "How many primary insurance policies are currently active for each plan_id? Show plan_id and active_count." }, { "role": "assistant", "content": "SELECT plan_id,\n COUNT(*) AS active_count\nFROM healthcare.patient_insurance\nWHERE is_primary = TRUE\n AND (expiration_date IS NULL OR expiration_date > CURRENT_DATE)\nGROUP BY plan_id;" } ]
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 // Use Hashes for ticket details. Key format: ticket:<ticket_id> // HSET ticket:tkt_1a2b ticket_id "tkt_1a2b" booking_id "book_zyx" car_id "car_abc" seat_number "12A" ... is_checked_in 0 ... // To link tickets to bookings (optional): // SADD booking:book_zyx:tickets ticket:tkt_1a2b // Use Hashes for maintenance record details. Key format: maintenance_record:<record_id> // HSET maintenance_record:maint_rec_001 record_id "maint_rec_001" asset_id "train_789" asset_type "Train" ... status "Completed" // To link records to assets (optional): // SADD train:train_789:maintenance maintenance_record:maint_rec_001 // SADD platform:plat_123:maintenance maintenance_record:maint_rec_002 ##Table Structure CREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) ) CREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) ) ##Table Structure CREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) ) CREATE TABLE transportation.drivers ( driver_id character varying(64) NOT NULL, employee_id character varying(64) NOT NULL UNIQUE, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, license_number character varying(64) NOT NULL UNIQUE, license_expiry_date date NOT NULL, contact_number character varying(32), email character varying(128) UNIQUE, hire_date date NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (driver_id) ) CREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, route_id character varying(64), vehicle_id character varying(64) NOT NULL, driver_id character varying(64) NOT NULL, scheduled_departure timestamp with time zone NOT NULL, actual_departure timestamp with time zone, scheduled_arrival timestamp with time zone NOT NULL, actual_arrival timestamp with time zone, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, status character varying(32) NOT NULL, passenger_count integer, cargo_manifest_id character varying(64), PRIMARY KEY (trip_id) ) CREATE TABLE transportation.locations ( location_id character varying(64) NOT NULL, name character varying(255) NOT NULL, type character varying(64) NOT NULL, address_line1 character varying(255), city character varying(128), state_province character varying(128), postal_code character varying(32), country character varying(64) NOT NULL, latitude numeric(9, 6), longitude numeric(9, 6), timezone character varying(64), PRIMARY KEY (location_id) ) CREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) ) CREATE TABLE transportation.passengers ( passenger_id character varying(64) NOT NULL, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32) UNIQUE, date_of_birth date, loyalty_program_id character varying(64), created_at timestamp with time zone NOT NULL, PRIMARY KEY (passenger_id) ) ##Table Structure CREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp ) ##Table Structure CREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp ) ##Table Structure CREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )
[ { "role": "user", "content": "特定の予約ID 'book_zyx' に関連するすべてのチケットの詳細を取得するのを手伝っていただけますか?また、関連する車両情報も含めてください。" }, { "role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGETALL ticket:<ticket_id>\nHGETALL car:<car_id>" }, { "role": "user", "content": "チェックイン済みのチケットだけを表示するようにフィルタリングしていただけますか?" }, { "role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGET ticket:<ticket_id> is_checked_in\nHGETALL ticket:<ticket_id> (only if is_checked_in = 1)\nHGETALL car:<car_id>" }, { "role": "user", "content": "座席番号も結果に含めて、座席番号順に並べ替えることは可能ですか?" }, { "role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGET ticket:<ticket_id> is_checked_in\nHGETALL ticket:<ticket_id> (only if is_checked_in = 1)\nHGETALL car:<car_id>\n(Sort results by seat_number in ascending order)" }, { "role": "user", "content": "車両IDごとにチケットの総数を追加していただけますか?" }, { "role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGET ticket:<ticket_id> is_checked_in\nHGETALL ticket:<ticket_id> (only if is_checked_in = 1)\nHGETALL car:<car_id>\n(Group by car_id and count total tickets per car_id)\n(Sort results by seat_number in ascending order)" }, { "role": "user", "content": "For each patient, count the total number of medical records they have in the system, and show patient_id along with record_count." }, { "role": "assistant", "content": "SELECT patient_id,\n COUNT(*) AS record_count\nFROM healthcare.medical_records\nGROUP BY patient_id;" }, { "role": "user", "content": "List all trips including the name of the origin location and the name of the destination location." }, { "role": "assistant", "content": "SELECT t.trip_id, origin.name AS origin_location_name, destination.name AS destination_location_name FROM transportation.trips t JOIN transportation.locations origin ON t.origin_location_id = origin.location_id JOIN transportation.locations destination ON t.destination_location_id = destination.location_id;" }, { "role": "user", "content": "Retrieve the count of active insurance products for each product_type and order the results by the count descending." }, { "role": "assistant", "content": "SELECT product_type,\n COUNT(*) AS active_count\nFROM insurance.insurance_products\nWHERE is_active = TRUE\nGROUP BY product_type\nORDER BY active_count DESC;" }, { "role": "user", "content": "List all pairs of wallets that use the same private_key. Display w1.wallet_id, w1.user_id, w2.wallet_id, w2.user_id, and the shared private_key." }, { "role": "assistant", "content": "SELECT w1.wallet_id AS wallet1_id,\n w1.user_id AS user1_id,\n w2.wallet_id AS wallet2_id,\n w2.user_id AS user2_id,\n w1.private_key\nFROM web3.wallets w1\nJOIN web3.wallets w2\n ON w1.private_key = w2.private_key\n AND w1.wallet_id < w2.wallet_id;" }, { "role": "user", "content": "List all asset symbols where the asset type is 'token'." }, { "role": "assistant", "content": "SELECT symbol FROM trading_platform.assets WHERE type = 'token';" } ]
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 character varying(64) NOT NULL, -- unique identifier for the user username character varying(50) NOT NULL UNIQUE, -- user's unique handle email character varying(128) NOT NULL UNIQUE, -- user's email address password_hash text NOT NULL, -- hashed password full_name character varying(100), -- user's full name profile_picture_url text, -- URL to the profile picture bio text, -- short user biography location character varying(100), -- user's location created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update is_verified boolean NOT NULL DEFAULT false, -- verification status PRIMARY KEY (user_id) ) CREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, -- unique identifier for the post user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id) content text, -- textual content of the post media_url text, -- URL to attached media (image/video) media_type character varying(20), -- type of media ('image', 'video', null) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private') location_lat numeric(9,6), -- latitude of post location location_lon numeric(9,6), -- longitude of post location PRIMARY KEY (post_id) ) CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, -- unique identifier for the comment post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id) user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id) parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id) content text NOT NULL, -- textual content of the comment created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit PRIMARY KEY (comment_id) ) CREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, -- unique identifier for the like user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id) post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable) comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something ) CREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id) following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows ) CREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used PRIMARY KEY (hashtag_id) ) CREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id) hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id) PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post ) CREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, -- unique identifier for the message conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id) sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id) content text, -- textual content of the message media_url text, -- URL to attached media (image/video) media_type character varying(20), -- type of media ('image', 'video', null) sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent read_at timestamp, -- timestamp when message was read by recipient(s) PRIMARY KEY (message_id) ) CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated last_message_at timestamp, -- timestamp of the last message in the conversation is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message group_name character varying(100), -- name of the group chat (if applicable) PRIMARY KEY (conversation_id) ) CREATE TABLE social_media.conversation_participants ( participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id) user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id) joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation last_read_at timestamp, -- timestamp indicating up to when the user has read messages PRIMARY KEY (participant_id), CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times ) CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, -- unique identifier for the notification recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id) sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications) notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message') target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id) target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created read_at timestamp, -- timestamp notification was marked as read PRIMARY KEY (notification_id) ) ##Table Structure CREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean ) CREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text ) ##Table Structure CREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )
[ { "role": "user", "content": "Show me the usernames and email addresses for users who have a non-empty bio and are verified." }, { "role": "assistant", "content": "SELECT username, email FROM social_media.users WHERE bio IS NOT NULL AND bio != '' AND is_verified = TRUE;" }, { "role": "user", "content": "Show all insurance plans where the plan name includes the word 'Care'." }, { "role": "assistant", "content": "SELECT plan_id, plan_name, insurance_provider, plan_type\nFROM healthcare.insurance_plans\nWHERE plan_name ILIKE '%Care%';" }, { "role": "user", "content": "How many documents were uploaded in the year 2023?" }, { "role": "assistant", "content": "SELECT count(*) FROM government_services.documents WHERE date_part('year', upload_timestamp) = 2023;" } ]
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
1