如何在Tableau中编写SQL提取offer_custom_fields表的Vacation Days对应值?
Fixing Your Custom SQL Query for Tableau
Let's get that query working right! The main issue with your current code is the invalid nested WHERE clause inside your condition—SQL doesn't allow that structure. Here's how to fix it, plus an option if you need to join with the offers table as you mentioned.
Basic Corrected Query
If you just need the offer_id and corresponding display_value for the 'Vacation Days' custom field from offer_custom_fields:
SELECT offer_id, display_value AS vacation_days FROM offer_custom_fields WHERE custom_field = 'Vacation Days'
Query with Join to offers Table
Since you noted the two tables are linked via offer_id, here's how to combine them if you need additional data from the offers table (like candidate details, offer dates, etc.):
SELECT o.offer_id, ocf.display_value AS vacation_days -- Uncomment and add fields from offers as needed: -- o.candidate_name, o.offer_date FROM offers o INNER JOIN offer_custom_fields ocf ON o.offer_id = ocf.offer_id WHERE ocf.custom_field = 'Vacation Days'
Key Fixes & Improvements:
- Removed the invalid nested
WHEREclause—we directly checkcustom_field = 'Vacation Days'in the outerWHERE. - Added a column alias (
vacation_days) to make the output column name more descriptive. - Used table aliases (
oforoffers,ocfforoffer_custom_fields) to simplify the code and avoid column name conflicts. - Swapped curly quotes (
‘’) for straight single quotes (')—most SQL engines (including those used with Tableau) require straight quotes for string literals.
内容的提问来源于stack exchange,提问作者nick lanta
相关产品推荐
相关产品推荐

