ETL SQL Statement
Hi,
I'm not familiar with SQL and wondering if someone can help with a SQL statement in an ETL that would solve the below(hope it makes sense)...
COLUMN1(txt) | COLUMN2(date) | COLUMN3(date) |
datapoint1 | oct 18 2020 | if 'column1' = 'datapoint1' then 'column2' minus 1 mth from the datafield in Col2' |
datapoint2 | oct 18 2020 | if 'column1' = 'datapoint2' then 'column2' minus 2 mths from the datafield in Col2' |
result...
COLUMN1(txt) | COLUMN2(date) | COLUMN3(date) |
datapoint1 | oct 18 2020 | Sept 2020 |
datapoint2 | oct 18 2020 | August 2020 |
Best Answer
-
If you are using MySQL, you could do this:
SELECT Column1, Column2, CASE WHEN column1 = 'datapoint1' THEN DATE_SUB(column2, INTERVAL 1 MONTH) WHEN column1 = 'datapoint2' THEN DATE_SUB(column2, INTERVAL 2 MONTH) END as Column3 FROM MyTable
You can also do this in MagicETL, which might be worth doing if you are not comfortable with SQL. You would use the Filter tile to split your data into two groups: datapoint1 and datapoint2. You would then use the Date Operations tile on both of those and use the subtract from date function in the tile and subtract 1 month for datapoint1 and 2 months for datapoint2. You would then use the Append tile to bring the datasets back together.
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1
Answers
-
If you are using MySQL, you could do this:
SELECT Column1, Column2, CASE WHEN column1 = 'datapoint1' THEN DATE_SUB(column2, INTERVAL 1 MONTH) WHEN column1 = 'datapoint2' THEN DATE_SUB(column2, INTERVAL 2 MONTH) END as Column3 FROM MyTable
You can also do this in MagicETL, which might be worth doing if you are not comfortable with SQL. You would use the Filter tile to split your data into two groups: datapoint1 and datapoint2. You would then use the Date Operations tile on both of those and use the subtract from date function in the tile and subtract 1 month for datapoint1 and 2 months for datapoint2. You would then use the Append tile to bring the datasets back together.
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1 -
Thanks Mark, it worked! One thing - instead of a filter tile I used Group By and added the sql statement mentioned above in the Formula box. Thanks again!
0 -
... i don't know your data, but i'm not sure why you'd do it in a GROUP BY instead of a FORMULA tile.
Also, instead of managing crazy math with a CASE statement, create an Interval column that says how many months to go back (i.e. 1 or 2) and then use your Formula (or GROUP BY) tile to pass the interval (number of months) as a variable.
Jae Wilson
Check out my 🎥 Domo Training YouTube Channel 👨💻
**Say "Thanks" by clicking the ❤️ in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
Hello @nj-John-mirc ,
I'm happy to let you know we have just released Code Block apps in our Domo Appstore. These allow customers and Domo experts such as yourself, to publish code blocks like the ones you've created for distribution in the Appstore. The publish process for the code blocks is currently in an early beta. The supported code blocks are:
- Beast Mode- SQL
- R
- Python
- Jupyter Notebook
If you are interested in publishing your code blocks, let me know and we can enable it for you.Cheers,
Cody SmithDirector of Product, Domo
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 297 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 614 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 729 Beast Mode
- 53 App Studio
- 40 Variables
- 677 Automate
- 173 Apps
- 451 APIs & Domo Developer
- 45 Workflows
- 8 DomoAI
- 34 Predict
- 14 Jupyter Workspaces
- 20 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 121 Manage
- 118 Governance & Security
- Domo Community Gallery
- 32 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive