CASE WHEN... AND in SQL ERROR
I'm working in MYSQL and trying to write a CASE WHEN Statement with multiple AND X<Y conditions. When it is finished, the statement below will be much longer with 15 more AND conditions, but right now this shorter version won't verify. The purpose of this statement is simply to find the lowest value across 15 columns for each row. Thoughts on what is going wrong (or perhaps a simplier way to find the minimum?? (The "min" function only finds the lowest value out of all the rows in the column (and not out of all the columns in a row, whic is what I'm trying to find). Thanks!
SELECT
CASE WHEN `Venturer_Dist`< `Strategist_Dist` AND `Venturer_Dist`< `Operator_Dist`
THEN 'Venturer'
END
FROM transform_data_3
Best Answer
-
Ok,
Try:
SELECT
CASE WHEN `Venturer_Dist`< `Strategist_Dist` AND `Venturer_Dist`< `Operator_Dist`
THEN 'Venturer' END AS ColumnName
FROM transform_data_3changes in Bold italic
If you are using this is a dataflow try also to loose the "`" :
SELECT
CASE WHEN Venturer_Dist < Strategist_Dist AND Venturer_Dist < Operator_Dist
THEN 'Venturer' END AS ColumnName
FROM transform_data_3Let me know how it goes.
Ricardo Granada
**If the post solves your problem, mark it by clicking on "Accept as Solution"
**You can say "Thank you" by clicking the thumbs up in the post that helped you.2
Answers
-
Hi,
What's the error?
Can/did you run transform_data_3 correctly?
Regards,
Ricardo Granada
**If the post solves your problem, mark it by clicking on "Accept as Solution"
**You can say "Thank you" by clicking the thumbs up in the post that helped you.0 -
Hi Ricardo,
This is the error message:
The database reported a syntax error. Incorrect column name 'CASE WHEN `Venturer_Dist`< `Strategist_Dist` AND `Venturer_Dist`< `Operator_Dist` THEN 'Venturer' E'
transform_data_3 is running smoothly!
Thanks,
Sarah
0 -
The first solution worked! Thanks for your help!
1
Categories
- 7.7K All Categories
- Connect
- 918 Connectors
- 242 Workbench
- 476 Transform
- 1.8K Magic ETL
- 60 SQL DataFlows
- 446 Datasets
- 35 Visualize
- 198 Beast Mode
- 2K Charting
- 8 Variables
- 1 Automate
- 348 APIs & Domo Developer
- 82 Apps
- Workflows
- 14 Predict
- 3 Jupyter Workspaces
- 11 R & Python Tiles
- 241 Distribute
- 59 Domo Everywhere
- 241 Scheduled Reports
- 15 Manage
- 36 Governance & Security
- 23 Product Ideas
- 1.1K Ideas Exchange
- Community Forums
- 15 Getting Started
- 1 Community Member Introductions
- 49 Community News
- 18 Event Recordings
- 579 日本支部